Answer to Question #213724 in Electrical Engineering for sajad

Question #213724

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?



1
Expert's answer
2021-07-05T04:54:54-0400
#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";
                }
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

sa
05.07.21, 01:15

I am waiting for the answer

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS