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

// (a) print the name and courseCode of the dynamically created course above to

ID: 3691553 • Letter: #

Question

// (a) print the name and courseCode of the dynamically created course above to screen // ...

// (b) change the value of courseCode of the dynamically created course above to "BIO 101" // ...

// (c) print the name and code of the dynamically created course above again on the screen // ... //

#include #include 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() { // creating one course dynamically courseType *coursePtr = new courseType("Biology I");

// (a) print the name and courseCode of the dynamically created course above to screen // ...

// (b) change the value of courseCode of the dynamically created course above to "BIO 101" // ...

// (c) print the name and code of the dynamically created course above again on the screen // ... // de-allocating memory delete coursePtr; system("pause"); return 0; }

Explanation / Answer

#include <iostream>
#include <string>
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() {
// creating one course dynamically
courseType *coursePtr = new courseType("Biology I");
// (a) print the name and courseCode of the dynamically created course above to screen // ...
cout << "Name:" << coursePtr->getName() << endl;
cout << "Code:" << coursePtr->getCode() << endl;
// (b) change the value of courseCode of the dynamically created course above to "BIO 101" // ...
coursePtr->setCode("BIO 101");
// (c) print the name and code of the dynamically created course above again on the screen // ...
cout << "Name:" << coursePtr->getName() << endl;
cout << "Code:" << coursePtr->getCode() << endl;
// de-allocating memory
delete coursePtr;
system("pause");
return 0;
}