I'm trying to figure out how to create new objects based on user input. Here is a sample output to help my description:
Enter value for object: 4 // this would set a value for object1 as 4
Do you want to enter another? yes
Enter value for object: 3 // this would set a value for object2 as 3
repeat...
Here is what I have without any logic for creating the new object in the loop (this program just overwrites the "object" object in each loop instead of making object1, object2, object3 etc...:
Thanks for your time
Hail to the Redskins.
Code:#include <iostream> using namespace std; class CRecord { public: CRecord(); //default constructor int getnum(); //get function int num; }; CRecord::CRecord() //default constructor { num=0; } int CRecord::getnum() // a get utility function { return num; } int main() { int counter =1; while ( counter <= 5 ) { CRecord object; cout << "enter value for object: " ; cin >> object.num; cout << endl << object.getnum() << endl; counter++; } return 0; }



LinkBack URL
About LinkBacks


