1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
|
#include <iostream>
#include <string>
using namespace std;
struct student{
long studentID;
string name;
float Grades[5];
};
//Home Assignment Structure
struct section{
int secNo;
int noStudents;
string roomNo;
student studentsList[20];
};
void getData(student &X);
void printData(student X);
float calculateAvg(student X);
bool equal(student X, student Y);
//Home Assignment Functions Prototype.
void GetData(section &mySection);
void PrintData(section mySection);
float averageQuiz1(section mySection);
void topStudents(section mySection);
int main()
{
float AVG;
bool isEqual=false;
student St1, St2;
cout<<"Enter the student info:\n"
<<"Student Name: ";
getline(cin, St1.name);
cout<<"Student ID: ";
cin>>St1.studentID;
cout<<"Student Grades(5): ";
for(int i=0; i<5; i++)
{
cin>>St1.Grades[i];
}
getData(St1);
printData(St1);
AVG=calculateAvg(St1);
cout<<"The average of quiz grades is: "<<AVG<<endl<<endl;
cout<<"Enter the 2nd student info:\n"
<<"Student Name: ";
getline(cin, St2.name);
getline(cin, St2.name);
cout<<"Student ID: ";
cin>>St2.studentID;
cout<<"Student Grades(5): ";
for(int i=0; i<5; i++)
{
cin>>St2.Grades[i];
}
isEqual=equal(St1, St2);
if(isEqual==true)
cout<<"Same Grades\n"<<endl;
else
cout<<"Different Grades\n"<<endl;
cout<<"**********\nHome Assignment\n**********\n"<<endl;
section mySection;
float QuizAv1=0;
GetData(mySection);
PrintData(mySection);
QuizAv1=averageQuiz1(mySection);
cout<<"\nThe average grade of first quiz for all students is: "
<<QuizAv1<<endl<<endl;
topStudents(mySection);
system("pause");
return 0;
}
void getData(student &X)
{
student St2;
St2.name=X.name;
St2.studentID=X.studentID;
for(int i=0; i<5; i++)
St2.Grades[i]=X.Grades[i];
}
void printData(student X)
{
cout<<endl<<"The data of student is:-"
<<"\nName: "<<X.name<<endl
<<"Student ID: "<<X.studentID<<endl<<"Grades: ";
for(int i=0; i<5; i++)
{
cout<<X.Grades[i];
if(i<5)
cout<<"\t";
}
cout<<endl;
}
float calculateAvg(student X)
{
float AV=0, SUM=0;
for(int i=0; i<5; i++)
SUM+=X.Grades[i];
AV=SUM/5;
return AV;
}
bool equal(student X, student Y)
{
for(int i=0; i<5; i++)
{
if(X.Grades[i] != Y.Grades[i])
return false;
}
return true;
}
//Home Assignment Functions
void GetData(section &mySection)
{
cout<<"Enter the section number: ";
cin>>mySection.secNo;
cout<<"Enter the room name/number: ";
getline(cin, mySection.roomNo);
getline(cin, mySection.roomNo);
cout<<"Enter the number of students: ";
cin>>mySection.noStudents;
cout<<"Enter the students details:\n";
if(mySection.noStudents > 20)
for(int i=0; i<20; i++)
{
cout<<i+1<<". "
<<"Enter student name: ";
getline(cin, mySection.studentsList[i].name);
getline(cin, mySection.studentsList[i].name);
cout<<"Enter student ID: ";
cin>>mySection.studentsList[i].studentID;
cout<<"Enter student grades (5): ";
for(int j=0; j<5; j++)
cin>>mySection.studentsList[i].Grades[j];
cout<<endl<<endl;
}
else
for(int i=0; i<mySection.noStudents; i++)
{
cout<<i+1<<". "
<<"Enter student name: ";
getline(cin, mySection.studentsList[i].name);
getline(cin, mySection.studentsList[i].name);
cout<<"Enter student ID: ";
cin>>mySection.studentsList[i].studentID;
cout<<"Enter student grades (5): ";
for(int j=0; j<5; j++)
cin>>mySection.studentsList[i].Grades[j];
cout<<endl<<endl;
}
}
void PrintData(section mySection)
{
cout<<endl<<endl<<"***\nSection Data\n***\n"<<endl;
cout<<"Section Number: "<<mySection.secNo<<endl
<<"Room Number: "<<mySection.roomNo<<endl
<<"Students Number: "<<mySection.noStudents<<endl
<<"Students Detials:-\n"<<endl;
if(mySection.noStudents>20)
for(int i=0; i<20; i++)
{
cout<<i+1<<". ";
cout<<"Name: "<<mySection.studentsList[i].name;
cout<<" || Student ID: "<<mySection.studentsList[i].studentID
<<endl;
cout<<" Student #"<<i+1<<" Grades: ";
for(int j=0; j<5; j++)
{
cout<<mySection.studentsList[i].Grades[j];
if(j<=4)
cout<<"\t";
}
cout<<endl<<endl;
}
else
for(int i=0; i<mySection.noStudents; i++)
{
cout<<i+1<<". ";
cout<<"Name: "<<mySection.studentsList[i].name;
cout<<" || Student ID: "<<mySection.studentsList[i].studentID
<<endl;
cout<<" Student #"<<i+1<<" Grades: ";
for(int j=0; j<5; j++)
{
cout<<mySection.studentsList[i].Grades[j];
if(j<=4)
cout<<"\t";
}
cout<<endl<<endl;
}
}
float averageQuiz1(section mySection)
{
float QuizAv1=0, SUM=0;
if(mySection.noStudents>20)
{
for(int i=0; i<20; i++)
SUM+=mySection.studentsList[i].Grades[0];
QuizAv1=SUM/20;
return QuizAv1;
}
else
{
for(int i=0; i<mySection.noStudents; i++)
SUM+=mySection.studentsList[i].Grades[0];
QuizAv1=SUM/mySection.noStudents;
return QuizAv1;
}
}
void topStudents(section mySection)
{
cout<<"Students names who got marks above the average:\n";
if(mySection.noStudents>20)
for(int i=0; i<20; i++)
if(mySection.studentsList[i].Grades[0] > averageQuiz1(mySection))
cout<<"Name: "<<mySection.studentsList[i].name<<"\tGrade: "<<mySection.studentsList[i].Grades[0];
else
for(int i=0; i<mySection.noStudents; i++)
if(mySection.studentsList[i].Grades[0] > averageQuiz1(mySection))
cout<<"Name: "<<mySection.studentsList[i].name<<"\tGrade: "<<mySection.studentsList[i].Grades[0];
}
|