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
|
#include <iostream>
#include <string>
using namespace std;
class Student {
string name;
int ID, mark;
public:
void set_values(string,int,int);
}
void Student::set_values(string a, int b, int c){
name = a;
ID = b;
mark = c;
}
int main(){
Student one, two, three;
string name_input;
int ID_input, mark_input;
for (int n=0; n<3; n++) {
cout << "Enter student information" << endl;
cout << "\nName: ";
getline(cin,name_input);
cout << "\nID: ";
getline(cin,ID_input);
cout << "\nMark: ";
getline(cin,mark_input);
if (n == 0)
one.set_values(name_input,ID_input,mark_input);
if (n == 1)
two.set_values(name_input,ID_input,mark_input);
if (n == 2)
three.set_values(name_input,ID_input,mark_input);
}
cout << one.name << " " << one.ID << " " << one.mark << " " << endl;
cout << two.name << " " << two.ID << " " << two.mark << " " << endl;
cout << three.name << " " << three.ID << " " << three.mark << " " << endl;
cout << "The average mark is " << (one.mark + two.mark + three.mark)/3;
}
|