Friday, July 31, 2009

C programming Question. Anyone who answers this Q i will give him my 10 points always when answering my Qs.?

Write a program that displays a menu that shows the following options:


a. Enter number of grades in class


b. Enter grades of class


c. Output average of class


d. Exit program





Choosing a menu option will cause some functionality to execute in order to have a program that calculate the average grade of a class:





a. Enter number of grades in class


Should allow the user to enter the number of grades to be inputted by the user. Do not allow the user to enter a 0 or negative number by displaying “invalid number” and prompting him to enter the number again...





b. Enter grades of class


Should allow the user to enter the number of grades of the class (you should calculate the sum)





c. Output average of class


Will print on the screen the average of the grade entered





d. Exit program


Will cause the program to terminate.

C programming Question. Anyone who answers this Q i will give him my 10 points always when answering my Qs.?
#include%26lt;stdio.h%26gt;


#include%26lt;process.h%26gt;


struct class


{


int no,gr[100],sum;


float avg;


};


typedef struct class CLASS


CLASS getnum();


CLASS getgrade():


CLASS cal_sum();


void display(CLASS C);


void main()


{


CLASS C1;


char op;


do


{


fflush(stdin);


printf("a.Enter number of grades in class


\nb.Enter grades of class


\nc.Output average of class


\nd.Exit program


\nEnter your choice:";


scanf("%c",%26amp;op);


switch(op)


{


case 'a':


c1=getnum();


break;


case 'b':


c1=getgrade(c1);


case 'c':


c1=cal_sum(c1);


display(c1);


break;


case 'd':


//Exit condition


exit(0);


default:


printf("Inavlid Option");


}while(1);


}


CLASS getnum()


{


CLASS t;


printf("Enter number of elements:");


scanf("%d",%26amp;t.no);


return t;


}


CLASS getgrade(CLASS t)


{


printf("Enter grades");


for(i=0;i%26lt;t.no;i++)


{


scanf("%d"%26amp;t.gr[i]);


if(t.gr[i]%26lt;=0)


{


printf("Invalid Input.Please Enter valid grade");


i--;


}


}


return t;


}


CLASS cal_sum(CLASS t)


{


t.sum=0;


for(i=0;i%26lt;=t.n;i++)


t.sum+=t.gr[i];


t.avg=t.sum/t.no;


return t;


}


void display(CLASS t)


{


printf("Sum:%d\nAverage:%.2f",t.sum,t.av...


}


//Please excuse any errors
Reply:So let me understand... All we have to do is write this program for you and you'll give us 10 points?





How many points is your teacher going to give you for turning in our work?


No comments:

Post a Comment