Using Microsoft Visual Studio create a C++ program that solves the following pro
ID: 3690983 • Letter: U
Question
Using Microsoft Visual Studio create a C++ program that solves the following problem. 1. Read the problem. Create a project that includes a class definition, an object of that class type, and passes a value from the object to the main program. Your program must contain the following attributes: a. A class named HoldValueClass and a derived object named HoldValueObject. b. The class should include a member that holds the string your name. c. The class should include a method that returns the string. d. The main code module should include only a main() function. The main() function should include only the object creation, a call to the class method that returns the string, and a command to display the string on the console. Please document the code.Explanation / Answer
#include<iostream>
using namespace std;
// class Defination
class HoldValueClass{
// member of class
string name; // holds name
public:
// constructor that takes a string as parameter
HoldValueClass(string n){
name = n; // setting parameter to member variable
}
// method that returns string value
string getName(){
return name;
}
};
// main method
int main(){
// creating a object of type HoldValueClass, with name "Alex Bob"
HoldValueClass HoldValueObject("Alex Bob");
// printg name
cout<<"Name: "<<HoldValueObject.getName()<<endl;
return 0;
}
/*
Output:
Name: Alex Bob
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.