Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

APPLY THE CONCEPT OF ENCAPSULATION A course in AGU has Course Code, Course Title

ID: 3875287 • Letter: A

Question

APPLY THE CONCEPT OF ENCAPSULATION A course in AGU has Course Code, Course Title, Credits, Lecture Hours, Lab Hours, and Prerequisite(s). Define a class Course with APPROPRIATE instance variables and methods including printCourse method that will print the information of a course object. The class MUST have two constructors; one should behave like a default constructor and other should have parameter list for all instance variables Write a test application and create an object of the class Course and print the information of the object using printCourse method Use set method to reset some values of the object created. The program will be assessed as per the following criteria.

Explanation / Answer

C+++ code :-

#include <iostream>
#include <string.h>
using namespace std;

/*Class Course Defination*/
class course{
private :
int code;
char title[100];
int credits;
int lect_hrs;
int lab_hrs;
char prerequisites[1000];

public:
/*default constructor*/
course()
{
code = 100;
strcpy(title,"c++");
credits = 100;
lect_hrs = 100;
lab_hrs = 100;
strcpy(prerequisites, "Understanding of c");
cout << "Defaul constructor called";
};

/*parametrized constructor*/
course(int code, char title[100], int credits, int lect_hrs, int lab_hrs,char prerequisites[1000])
{
this->code = code;
strcpy(this->title, title);
this->credits = credits;
this->lect_hrs = lect_hrs;
this->lab_hrs = lab_hrs;
strcpy(this->prerequisites, prerequisites);

};

/*This method prints all the information about thhe course*/
void printCourse()
{
cout << " Below are the detail of the Course: ";
cout << "Title :" << title;
cout << " Code :" << code;
cout << " Credits :" << credits;
cout << " Lecture hours :" << lect_hrs;
cout << " Lab hours" << lab_hrs;
cout << " Prerequisites :" << prerequisites;
cout << " ";
};

/*Method to update the lecture and lab hours*/
void setCourse_hrs(int lect_hrs, int lab_hrs)
{
this->lect_hrs = lect_hrs;
this->lab_hrs = lab_hrs;

}

};
/*End of class course defination*/

/*main function*/
int main(){

class course c1; /*creating the object of class*/
c1.printCourse(); /*printing the course object using member function*/
c1.setCourse_hrs(50, 50); /*calling the set method to update the course content*/
c1.printCourse(); /*printing the course object again to check the new changes*/

}
/*end of main*/

output screenshot:

]$ ./a.out
Defaul constructor called
Below are the detail of the Course:
Title :c++
Code :100
Credits :100
Lecture hours :100
Lab hours100
Prerequisites :Understanding of c


Below are the detail of the Course:
Title :c++
Code :100
Credits :100
Lecture hours :50
Lab hours50
Prerequisites :Understanding of c