Answer to Question #176213 in C++ for Christine

Question #176213

That accept the marks of 3 courses and accept the names of courses alongside the hours spent



1
Expert's answer
2021-03-28T00:32:15-0400
#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;
 }

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