Write an algorithm that will accept the following for 100 students: The students’ name (studName) and 3 test marks (marks), as well as one exam mark (examMark). The program must calculate the final mark (finMark) for every student. The final mark comprises of 50% of the exam mark added to 50% of the average (agv) of the 3 tests. Display the final mark for every student.
1.Mix the for loop with a do-while
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Student
{
public:
Student(string name, int exam, int mark1, int mark2, int mark3);
void Display();
private:
string nameS;
int examS;
int mark1S;
int mark2S;
int mark3S;
int finalMark;
};
Student::Student(string name, int exam, int mark1, int mark2, int mark3) : nameS(name), examS(exam), mark1S(mark1), mark2S(mark2), mark3S(mark3)
{
finalMark = (examS + (mark1S + mark2S + mark3S) / 3) / 2;
}
void Student::Display()
{
cout << nameS << ": " << finalMark << endl;
}
int main()
{
vector<Student> CLASS;
string name;
int exam, mark1, mark2, mark3;
// until quantity of students is 100 or we enter Student name 000
do
{
cout << "Enter student name (enter name 000 to exit): ";
cin >> name;
if (name == "000")
{
cout << "All student were entered!" << endl << endl;
break;
}
cout << "Enter exam: ";
cin >> exam;
cout << "Enter 3 mark using space: ";
cin >> mark1 >> mark2 >> mark3;
CLASS.push_back(Student(name, exam, mark1, mark2, mark3)); // put Student in class
} while (CLASS.size() < 101); // quantity student less than 101
// Display student that we have entered
cout << "Students in class!!" << endl;
int i = 0;
while (i < CLASS.size())
{
CLASS[i++].Display();
}
cout << "End of program" << endl;
system("pause");
return 0;
}
Comments
Leave a comment