Answer to Question #229585 in C++ for Arup

Question #229585

Write a program to create a class to store details of a student ( name, roll and 3 subject marks ). Input details for 2 students and assign all the details of that student who is having higher average mark to a new student.

i) use member function

ii) use friend function

1
Expert's answer
2021-08-26T07:45:22-0400
#include <iostream>
using namespace std; 
#define MAX 10
class student
{
    private:
        char  name1[30];
        int   rollNo1;
        int   total1;
        float average1;
        char  name2[30];
        int   rollNo2;
        int   total2;
        float average2;
    public:
        void getDetails(void);
        void putDetails(void);
};
 
//member function definition
void student::getDetails(void){
    cout << "Enter name of student1: " ;
    cin >> name1;
    cout << "Enter roll number: ";
    cin >> rollNo1;
    cout << "Enter total marks of the three subjects: ";
    cin >> total1;
    average1=(float)total1/3;
    cout << "Enter name of student2: " ;
    cin >> name2;
    cout << "Enter roll number: ";
    cin >> rollNo2;
    cout << "Enter total marks of the three subjects: ";
    cin >> total2;
     
    average2=(float)total2/3;
}
 
//friend function definition
void student::putDetails(void){
	if(average1> average2){
    cout << "New Student details:\n";
    cout << "Name:"<< name1 << ",Roll Number:" << rollNo1 << ",Total:" << total1 << ",Average:" << average1;}
    else{
    cout << "New Student details:\n";
    cout << "Name:"<< name2 << ",Roll Number:" << rollNo2 << ",Total:" << total2 << ",Average:" << average2;
	}
}
 
int main()
{
    student std[MAX];      
    int loop;
    cout << "Enter details of the 2 students "<< ":\n";
    std[loop].getDetails();


    cout << endl;
    cout << "Details of student " << ":\n";
    std[loop].putDetails();
    
     
    return 0;
}

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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS