-
September 14th, 2012, 06:35 PM
#1
Having problems with objects and classes
hi, I'm having problems with the code below. Can someone help me? When I run the program, I am unable to get the output of GetMissile, GetLaser,.. Also, instead of displaying the correct 'prices' for, for example You.MissilePrice(), I get numbers that don't make sense, such as -858993460
Code:
#include <iostream>
using namespace std;
class Aircraft
{
public:
Aircraft(){cout<<"aircraft constructor"<<endl;}
virtual ~Aircraft(){cout<<"aircraft destructor"<<endl;}
protected:
string Missile;
string Laser;
string Bomb;
string Propulsion;
int Price;
};
class Jet : public Aircraft
{
public:
string GetMissile() {return Missile;}
int MissilePrice() {return Price;}
string GetLaser() {return Laser;}
int LaserPrice() {return Price;}
string GetBomb() {return Bomb;}
int BombPrice() {return Price;}
string GetPropulsion() {return Bomb;}
int PropulsionPrice() {return Price;}
void SetMissile(int MissileChoice)
{
switch(MissileChoice)
{
case '0':
Missile = "AA";
Price = 150;
case '1':
Missile = "AS";
Price = 170;
case '2':
Missile = "ASM";
Price = 170;
case '3':
Missile = "ATM";
Price = 150;
}
}
void SetLaser(int LaserChoice)
{
switch(LaserChoice)
{
case '0':
Laser = "HF";
Price = 50;
case '1':
Laser = "DF";
Price = 70;
case '2':
Laser = "CO";
Price = 70;
case '3':
Laser = "AGI";
Price = 50;
}
}
void SetBomb(int BombChoice)
{
switch(BombChoice)
{
case '0':
Bomb = "CB";
Price = 300;
case '1':
Bomb = "COB";
Price = 400;
case '2':
Bomb = "IC";
Price = 400;
case '3':
Bomb = "GP";
Price = 350;
}
}
void SetPropulsion(int PropulsionChoice)
{
//Jet.Propulsion
switch(PropulsionChoice)
{
case '0':
Propulsion = "SP";
Price = 375;
case '1':
Propulsion = "LRP";
Price = 400;
case '2':
Propulsion = "EP";
Price = 200;
case '3':
Propulsion = "NP";
Price = 300;
}
}
//protected:
};
int main()
{
Jet You;
int MissileChoice, LaserChoice, BombChoice, PropulsionChoice;
cout<<"choose the missile, laser, bomb, propulsion of the jet"<<endl;
cin>>MissileChoice;
cin>>LaserChoice;
cin>>BombChoice;
cin>>PropulsionChoice;
You.SetMissile(MissileChoice);
You.SetLaser(LaserChoice);
You.SetBomb(BombChoice);
You.SetPropulsion(PropulsionChoice);
cout<<"you chose ";
You.GetMissile();
You.GetLaser();
You.GetBomb();
You.GetPropulsion();
cout<<"total price is "<<You.MissilePrice()<<" + "<<You.LaserPrice()<<" + ";
cout<<You.BombPrice()<<" + "<<You.PropulsionPrice()<<" = ";
cout<<You.MissilePrice()+You.LaserPrice()+You.BombPrice()+You.PropulsionPrice();
cin.ignore();
cin.ignore();
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|