Post by bfr on Nov 22, 2005 16:28:19 GMT -5
I'm the only one who ever goes here, so I guess I'm posting to myself.
Here is some C++ code that demonstrates the use of OOP:
If you look at it carefully, I think it really could help somebody learn the basics of OOP and classes. I'd be happy to explain it to anybody.
Also, if you input text that isn't a number for when it says, "Input 1 to...", then the program repeats "You didn't enter a valid value" forever . If you enter a number that isn't 1,2 or 3, then it just says that you didn't enter a valid value once.
Copy and paste the below URL to your browser, to download the .exe version. When I give the direct link, Proboards redirects back to this page.
www.freewebs.com/vdesignfiles/oopexample.exe
Here is some C++ code that demonstrates the use of OOP:
//OOP Example - Joeman345 of VDesign
//Note that this includs a bunch of uneeded but fun stuff
//I used strings in some cases to avoid errors easily
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <cstdio>
#include <cstdlib>
using namespace std;
int dosomething;
string namep;
string hobbyp;
string agep;
class Person{
public:
string pname;
string phobby;
string page;
void greet(){
cout << "Hello, my name is " << pname << "." << endl;
cout << "\n I am " << page << " years old." << endl;
}
};
int main(){
while(dosomething != 3){
cout << "Input the data to create your new person \n" << endl;
cout << "Name" << endl;
cin >> namep;
cout << "Age" << endl;
cin >> agep;
cout << "Hobby" << endl;
cin >> hobbyp;
Person myPerson;
myPerson.pname = namep;
myPerson.phobby = hobbyp;
myPerson.page = agep;
cout << "\n Input 1 to have the person greet you." << endl;
cout << "\n Input 2 to display your person's data." << endl;
cout << "\n Input 3 to stop the program." << endl;
cin >> dosomething;
switch(dosomething){
case 1:
myPerson.greet();
break;
case 2:
cout << "\n Name: " << myPerson.pname << endl;
cout << "\n Age: " << myPerson.page << endl;
cout << "\n Hobby: " << myPerson.phobby << endl;
break;
case 3:
system("PAUSE");
return 0;
break;
default:
cout << "You didn't enter a valid value!" << endl;
}
system("PAUSE");
}
}
If you look at it carefully, I think it really could help somebody learn the basics of OOP and classes. I'd be happy to explain it to anybody.
Also, if you input text that isn't a number for when it says, "Input 1 to...", then the program repeats "You didn't enter a valid value" forever . If you enter a number that isn't 1,2 or 3, then it just says that you didn't enter a valid value once.
Copy and paste the below URL to your browser, to download the .exe version. When I give the direct link, Proboards redirects back to this page.
www.freewebs.com/vdesignfiles/oopexample.exe