An educational institution wish to maintain a database of its students, the database is divided into a members of classes whose multiple relationships are shown in fig.1,find:
a-Initialize the five data members by using constructor? b-Calculate average of two marks (using friend function)? c-Display all database information where the student is successful?
#include<iostream>
using namespace std;
class student{
public:
string code;
string name;
};
class course{
public:
int course_no;
};
class test{
public:
int mark1,mark2;
friend double average(test& t){
return (t.mark1+t.mark2)/2;
}
};
class result{
test t;
student s;
course c;
public:
// intialize 5 data memeber using constructor
result(string code,string name,int course_no,int mark1,int mark2){
t.mark1 = mark1;
t.mark2 = mark2;
s.code = code;
s.name = name;
c.course_no = course_no;
}
// calculate average of 2 marks (using frined function)
double calculate(){
return average(t);
}
// display all database information where the student is successfull
double display(){
cout<<"Name: "<<s.name<<"\tCode: "<<s.code<<"\n";
cout<<"Course no: "<<c.course_no<<"\n";
cout<<"Test Mark1: "<<t.mark1<<"\tTest Mark2: "<<t.mark2<<"\n";
}
};
Comments
I am waiting for the answer
Leave a comment