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

.....the code that I have so far as below .......... class courseType { private:

ID: 3686629 • Letter: #

Question

.....the code that I have so far as below ..........

class courseType
{
private:

   string name;
   string courseCode;

public:

   courseType(string theName = "Default name", string theCode= "Default code")
   {
       name = theName;
       courseCode = theCode;
   }

   string getName() const { return name; }
   string getCode() const { return courseCode; }

   void setName(string newName) {name = newName; }
   void setCode(string newCode) {courseCode = newCode; }

};

int main()
{
  

   courseType *coursePtr = new courseType("Biology I");


   delete coursePtr;

   system("pause");
   return 0;
}

Write a C++ program : About Pointers and Classes and Dynamic Memory Allocation

Question: in Int Main :

a. creating one course dynamically
b. print the name and courseCode of the dynamically created course above to screen
c. change the value of courseCode of the dynamically created course above to "BIO 101"
d. print the name and code of the dynamically created course above again on the screen
e. de-allocating memory

Explanation / Answer

#include<iostream>
#include<cstdlib>

using namespace std;

class courseType
{
private:

string name;
string courseCode;

public:

courseType(string theName = "Default name", string theCode= "Default code")
{
name = theName;
courseCode = theCode;
}

string getName() const { return name; }
string getCode() const { return courseCode; }

void setName(string newName) {name = newName; }
void setCode(string newCode) {courseCode = newCode; }

};

int main()
{
  
   //a
courseType *coursePtr = new courseType("CSE","CS4003");
//b
cout<<"Course Name: "<<coursePtr->getName()<<", abd Course Code: "<<coursePtr->getCode()<<endl;
//c
coursePtr->setCode("BIO 101");
//d
cout<<"Course Name: "<<coursePtr->getName()<<", abd Course Code: "<<coursePtr->getCode()<<endl;
//e
delete coursePtr;

system("pause");
return 0;
}

/*

Output:

Course Name: CSE, abd Course Code: CS4003
Course Name: CSE, abd Course Code: BIO 101

*./