By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,603 Members | 1,477 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,603 IT Pros & Developers. It's quick & easy.

Need help !emergency

P: 7
my probgram doesn't show the total mark and the grade1
can any one solve the problem?
this is easy thing but i vahe only 15 min to solve it



#include<iostream>
#include<string>
using namespace std;
struct studentType
{
string Fname;
string Lname;
string add;
string DOB;

char grade;
int tot;
int first;
int mid;
int lab;
int final;
int score;
};
void Readstudents(studentType st[],int & size);
void calculateTotalMark(studentType st[], int size);
void findGrade(studentType st[], int size);
int CalculateAverage(studentType st[],int size);
void DisplayBelowAvrage(studentType st[],int i,int avg,int size);

int main( )
{
studentType st[100];
int avrg, size=0,k=0;
Readstudents(st,size);
calculateTotalMark(st,size);
findGrade(st, size);
avrg=CalculateAverage(st,size);
DisplayBelowAvrage(st,k,avrg,size);


return 0;
}
void Readstudents(studentType st[],int & i)
{
bool t=true;
for( i=0;i<100 && t;i++)
{
cout<<"Enter students information \n"
<<"To stop reading information enter -999 \n";
cin>>st[i].Fname;
if (st[i].Fname!="-999")
{
cout<<"Enter last name"<<endl;
cin>>st[i].Lname;
cout<<"Enter student address \n";
cin>>st[i].add;
cout<<"Enter student Date of Birth \n";
cin>>st[i].DOB;
do{
cout<<"Enter student marks"<<endl<<"First exam ";
cin>>st[i].first;
}while(st[i].first<0 || st[i].first>10);

do{
cout<<"Midterm exam ";
cin>>st[i].mid;
}while(st[i].mid<0 || st[i].mid>20);
do{
cout<<"Lab ";
cin>>st[i].lab;
}while(st[i].lab<0 || st[i].lab>30);

do{
cout<<"Final exam ";
cin>>st[i].final;
}while(st[i].final<0 || st[i].final>40);
}
else
t=false;
}
}
void calculateTotalMark(studentType st[], int size)
{
int i;
for(i=0;i<size;i++)
st[i].tot=st[i].first+st[i].mid+st[i].lab+st[i].final;
cout<<st[i].tot<<endl;
}
void findGrade(studentType st[], int size)
{
for (int i=0; i<size; i++)
{
if(st[i].score<60)
st[i].grade='F';
else if(st[i].score<70)
st[i].grade='D';
else if(st[i].score<80)
st[i].grade='C';
else if(st[i].score<90)
st[i].grade='B';
else st[i].grade='A';
}
cout<<"the grade is:"<<" "<<st[i].grade<<endl;
}
int CalculateAverage(studentType st[], int size)
{
int i,avg,sum=0;
for(i=0;i<size;i++)
sum=sum+st[i].tot;
avg=sum/size;
return avg;
}
void DisplayBelowAvrage(studentType st[],int i,int avg,int size)
{
cout<<"The class average = "<<avg<<endl;
for (i=0;i<size-1; i++)
{
if (st[i].score<avg)

cout<<endl<<endl<<endl<<st[i].Fname<<" "<<st[i].Lname<<" "<<st[i].add<<" "
<<st[i].DOB<<" "<<st[i].tot<<endl;
}
}
Nov 15 '06 #1
Share this Question
Share on Google+
5 Replies


10K+
P: 13,264
my probgram doesn't show the total mark and the grade1
can any one solve the problem?
this is easy thing but i vahe only 15 min to solve it



#include<iostream>
#include<string>
using namespace std;
struct studentType
{
string Fname;
string Lname;
string add;
string DOB;

char grade;
int tot;
int first;
int mid;
int lab;
int final;
int score;
};
void Readstudents(studentType st[],int & size);
void calculateTotalMark(studentType st[], int size);
void findGrade(studentType st[], int size);
int CalculateAverage(studentType st[],int size);
void DisplayBelowAvrage(studentType st[],int i,int avg,int size);

int main( )
{
studentType st[100];
int avrg, size=0,k=0;
Readstudents(st,size);
calculateTotalMark(st,size);
findGrade(st, size);
avrg=CalculateAverage(st,size);
DisplayBelowAvrage(st,k,avrg,size);


return 0;
}
void Readstudents(studentType st[],int & i)
{
bool t=true;
for( i=0;i<100 && t;i++)
{
cout<<"Enter students information \n"
<<"To stop reading information enter -999 \n";
cin>>st[i].Fname;
if (st[i].Fname!="-999")
{
cout<<"Enter last name"<<endl;
cin>>st[i].Lname;
cout<<"Enter student address \n";
cin>>st[i].add;
cout<<"Enter student Date of Birth \n";
cin>>st[i].DOB;
do{
cout<<"Enter student marks"<<endl<<"First exam ";
cin>>st[i].first;
}while(st[i].first<0 || st[i].first>10);

do{
cout<<"Midterm exam ";
cin>>st[i].mid;
}while(st[i].mid<0 || st[i].mid>20);
do{
cout<<"Lab ";
cin>>st[i].lab;
}while(st[i].lab<0 || st[i].lab>30);

do{
cout<<"Final exam ";
cin>>st[i].final;
}while(st[i].final<0 || st[i].final>40);
}
else
t=false;
}
}
void calculateTotalMark(studentType st[], int size)
{
int i;
for(i=0;i<size;i++)
st[i].tot=st[i].first+st[i].mid+st[i].lab+st[i].final;
cout<<st[i].tot<<endl;
}
void findGrade(studentType st[], int size)
{
for (int i=0; i<size; i++)
{
if(st[i].score<60)
st[i].grade='F';
else if(st[i].score<70)
st[i].grade='D';
else if(st[i].score<80)
st[i].grade='C';
else if(st[i].score<90)
st[i].grade='B';
else st[i].grade='A';
}
cout<<"the grade is:"<<" "<<st[i].grade<<endl;
}
int CalculateAverage(studentType st[], int size)
{
int i,avg,sum=0;
for(i=0;i<size;i++)
sum=sum+st[i].tot;
avg=sum/size;
return avg;
}
void DisplayBelowAvrage(studentType st[],int i,int avg,int size)
{
cout<<"The class average = "<<avg<<endl;
for (i=0;i<size-1; i++)
{
if (st[i].score<avg)

cout<<endl<<endl<<endl<<st[i].Fname<<" "<<st[i].Lname<<" "<<st[i].add<<" "
<<st[i].DOB<<" "<<st[i].tot<<endl;
}
}
Perhaps calculateTotalMark should really be looking like

Expand|Select|Wrap|Line Numbers
  1.  
  2. void calculateTotalMark(studentType st[], int size)
  3. {
  4. int i;
  5. int total = 0;
  6. for(i=0;i<size;i++) {
  7.     st[i].tot=st[i].first+st[i].mid+st[i].lab+st[i].final;
  8.     total = total + st[i].tot; 
  9. }
  10. cout<<total<<endl;
  11. }
  12.  
  13.  
Nov 15 '06 #2

P: 7
it again shows somthing strange
i used to follow same way but it does n't work
Nov 15 '06 #3

P: 7
and this is the complete requierd program

Write a C++ program that calls the following functions:


a) READSTUDENTS that reads students’ Name, Address, Date of Birth, and 4 marks: First test mark (0 – 10), Midterm exam mark (0- 20), Lab mark (0-30) and Final exam mark (0-40).


b) CalculateTotalMark that calculates, for each student, the total mark earned (0 – 100).


c) FindGrade that finds the relevant character grade for each student.


d) CalculateAverage that calculates the Class average.


e) DisplayBelowAverage that displays students’ name, address and date of birth of with total mark below class average.


Notes:


1. The total number of students is not known in advance: You should find a way to stop reading students’ information!!


2. Store students’ information in an array of struct.


3. Choose appropriate parameters (calling by value / by reference) to all the functions needed.


4. Do not use global variables!!!
Nov 15 '06 #4

10K+
P: 13,264
it again shows somthing strange
i used to follow same way but it does n't work
Sorry I do not have a C++ compiler but what strange thing does it show?
Nov 15 '06 #5

P: 7
it shows some strange number


8887769586
Nov 15 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.