Using Microsoft Visual Studio create a C++ program that solves the following pro
ID: 3691085 • Letter: U
Question
Using Microsoft Visual Studio create a C++ program that solves the following problem.
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. 2. Create a new project. Visual C++ Win32 Console Application Select a location where you can find it later Choose the default application settings 3. Write the program. Write code that solves the problem described in item 1. Pause the program so that the console does not disappear until a key is pressed. 4. Insure that you properly document your 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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.