PLEASE CODE USING C++ Design a Course class that contains individual course info
ID: 3753551 • Letter: P
Question
PLEASE CODE USING C++
Design a Course class that contains individual course information and has the following private attributes long string int courseNumber courseName numberOfCredits All class attributes must be private and accessed through public member functions. You need to write the following public methods Default constructor that sets courseNumber to 0, courseName to "", and number ofCredits to 0 Overloaded constructor that takes 3 parameters used to initialize the 3 attributes. Set function(s) that set the objects data. Print function that displays the object data in a neat fashion. - - After you design your class, write a main program that instantiates 2 Course objects, sets and displays their information as described below: For the first object 1. Ask the user to enter the course number, name and number of credits (the user 2. 3. should enter for example 21541, CS211, and 1 respectively) Create the object using the overloaded constructor (and the data from above). Call the print function to print the object data. For example Course Numbe 21541 Course Name Number of Credits: 1 CS 211 For the second obiect: 1. Create the object using the default constructor 2. Call the print function to display the second object's data. 3. Prompt the user to enter new data for the second object (for example 21345, 4. 5. CS331, and 3) Call the set function(s) to set the object's attributes to the user input. Call the print function to display the new object data. Note: You must divide your files into .cpp and .h fileExplanation / Answer
Course.h file will contain:
#include<string>
using namespace std;
class Course
{
long courseNumber;
string courseName;
int numberOfCredit;
public:
Course()
{
courseNumber=0;
courseName="";
numberOfCredit=0;
}
Course(long courseNumber1,string courseName1,int numberOfCredit1)
{
courseNumber=courseNumber1;
courseName=courseName1;
numberOfCredit=numberOfCredit1;
}
void set_courseNumber(long courseNumber1)
{
courseNumber=courseNumber1;
}
void set_courseName(string courseName1)
{
courseName=courseName1;
}
void set_numberOfCredit(int numberOfCredit1)
{
numberOfCredit=numberOfCredit1;
}
void print_data()
{
cout<<"Course Number: "<<courseNumber<<endl;
cout<<"Course Name: "<<courseName<<endl;
cout<<"Number of credits: "<<numberOfCredit<<endl;
}
};
main.cpp file will contain code:
#include <iostream>
#include <string>
#include "Course.h"
using namespace std;
int main()
{
long courseNumber;
string courseName;
int numberOfCredit;
cout<<"Enter Course Number for Course1: "; //For the first object: 1.
cin>>courseNumber; //For the first object: 1.
cout<<"Enter Course Name for Course1: "; //For the first object: 1.
cin>>courseName; //For the first object: 1.
cout<<"Enter Number of Credits for Course1: "; //For the first object: 1.
cin>>numberOfCredit; //For the first object: 1.
Course c1(courseNumber,courseName,numberOfCredit); //For the first object: 2.
c1.print_data(); //For the first object: 3.
Course c2; //For the second object: 1.
c2.print_data(); //For the second object: 2.
cout<<"Enter Course Number for Course2: "; //For the second object: 3.
cin>>courseNumber; //For the second object: 3.
cout<<"Enter Course Name for Course2: "; //For the second object: 3.
cin>>courseName; //For the second object: 3.
cout<<"Enter Number of Credits for Course2: "; //For the second object: 3.
cin>>numberOfCredit; //For the second object: 3.
c2.set_courseNumber(courseNumber); //For the second object: 4.
c2.set_courseName(courseName); //For the second object: 4.
c2.set_numberOfCredit(numberOfCredit); //For the second object: 4.
c2.print_data(); //For the second object: 5.
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.