1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
#include <iostream>
#include <string>
//create a class called Bio
class Bio
{
//give access to variables outside the class
public:
std::string name; //create a string variable called name
int age; //create an integer variable called age
int weight; //create an integer variable called weight
float height; //create a float variable called height
std::string code;
//Constructor 1
Bio(std::string name2, int age2, int weight2, float height2)
{
name = name2;
age = age2;
weight = weight2;
height = height2;
}
//Constructor 2
Bio(std::string name3, int age3, float height3, int weight3)
{
name = name3;
age = age3;
weight = weight3;
height = height3;
}
//Constructor 3
Bio(std::string Sname, int age4, int weight4, float height4, std::string cheat)
{
code = cheat;
name = Sname;
age = age4;
weight = weight4;
height = height4;
}
};
using namespace std;
void selection();
std::string choice;
int main()
{
Bio obj("King Rhizord",350,510,6.11);
Bio obj2("Gozo",210,260,5.8);
Bio obj3("Syxx",103,135,5.5,"Up,Down,Left,Left,Down,Right,Down");
int CharBio;
cout << "A small program to show character bios" << endl;
cout << endl;
cout << "1) King Rhizord\n" << "2) Gozo\n" << "3) Syxx\n" <<
"4) Quit Program\n" << endl;
cout << "Please enter a number to view a characters Bio: ";
cin >> CharBio;
cout << endl;
if(CharBio == 1)
{
cout << "Name: " << obj.name << "\nAge: " << obj.age << "\nWeight: " <<
obj.weight << "\nHeight: " << obj.height << endl;
cout << endl;
selection();
}
else if(CharBio == 2)
{
cout << "Name: " << obj2.name << "\nAge: " << obj2.age << "\nWeight: " <<
obj2.weight << "\nHeight: " << obj2.height << endl;
cout << endl;
selection();
}
else if(CharBio == 3)
{
cout << "Name: " << obj3.name << "\nAge: " << obj3.age << "\nWeight: " <<
obj3.weight << "\nHeight: " << obj3.height << "\nCheat Code: " <<
obj3.code << endl;
cout << endl;
selection();
}
else if(CharBio == 4)
{
exit(0);
}
else
{
cout << "You have entered an incorrect number!" << endl;
}
cout << endl;
system("pause");
return 0;
}
void selection()
{
cout << "Would you like to view another characters Bio (y/n): ";
getline(cin, choice);
}
|