That accept the marks of 3 courses and accept the names of courses alongside the hours spent
#include <iostream>
using namespace std;
#define MAX 10
class course
{
private:
char name[30];
int marks;
int hours_spent;
public:
void getDetails(void);
void putDetails(void);
};
//member function definition, outside of the class
void course::getDetails(void){
cout << "Enter course: " ;
cin >> name;
cout << "Enter hours_spent: ";
cin >> hours_spent;
cout << "Enter total marks : ";
cin >> marks;
}
//member function definition, outside of the class
void course::putDetails(void){
cout << "Course details:\n";
cout << "Course Name:"<< name << "Marks:" << marks<< "," << hours_spent ;
}
int main()
{
course std[MAX]; //array of objects creation
int n,loop;
cout << "Enter total number of courses: ";
cin >> n;
for(loop=0;loop< n; loop++){
cout << "Enter details of course " << loop+1 << ":\n";
std[loop].getDetails();
}
cout << endl;
for(loop=0;loop< n; loop++){
cout << "Details of course" << (loop+1) << ":\n";
std[loop].putDetails();
}
return 0;
}
Comments
Leave a comment