number 2
// Debug 5-2
#include<iostream>
class UsedCar
{
private:
int vehicleID;
double price;
int year;
int miles;
double value;
void determineMileageRating();
public:
void setVehicleID()
void setPrice()
void displayUsedCar()
};
void UsedCar::setVehicleID()
{
cout<<"Enter vehicle ID - use 3 digits ";
cin>>vehicleID;
while(vehicleID < 99 && vehicleID > 1000)
{
cout<<"Use 3 digits please ";
cin>>vehicleID;
}
}
void UsedCar::setPrice()
{
cout<<"Enter price ";
cout>>price;
}
void UsedCar::setYear()
{
cout<<"Enter year of car ";
cin>>year;
while(year < 1940 && year > 2005)
{
cout<<"Check the year and reenter ";
cin<<year;
}
}
void UsedCar::setMiles()
{
cout<<"Enter miles on vehicle ";
cin>>miles;
determineMileageRating();
}
void UsedCar::determineMileageRating()
{
int yearsOld;
yearsOld = 2005 - year;
if(miles < yearsOld * 8000)
cout<<"This is a low mileage car";
else if(miles < yearsOld * 15000)
cout<<"This is an average mileage car";
else cout<<"That is a lot of miles for the age";
cout<<endl;
}
Number 4
// Debug 5-4
#include<iostream>
class Office
{
private:
int officeNum;
char tenant[30];
int rent;
static int rentDueDate;
public:
void setOfficeData(int num, char occupant[], int rent);
static void showRentDueDate();
void showOffice();
};
int rentDueDate = 1;
void Office::setOfficeData(int num, char occupant[], int rent)
{
officeNum = num;
strcpy(tenant, occupant);
rent = rent;
}
void Office::showOffice()
{
cout<<"Office "<<officeNum<<" is occupied by "<<tenant<<endl;
cout<<"The rent $"<<rent<<" is due on day "<<rentDueDate<<" of the month"<<endl;
}
void Office::showRentDueDate()
{
cout<"All rents are due on day "<rentDueDate<" of the month"<endl;
}
void main()
{
Office::showRentDueDate();
myOffice.setOfficeData(234,"Dr. Albright", 450);
myOffice.showOffice();
System ("pause");
}
private prevents using things. So for #1 your first problem is making all the methods you call in main private, where they can't be called because they are private... use public: on the ones you need to call from main, and private on the rest (and actual variables).
void main is not legal in standard c++. Avoid this style, though most windows compilers will accept it.
Going forward we can help but..
- please insert the code in code tag blocks
- please tell us what exactly is wrong with them
- lets work on one at a time maybe.
- is this one of those problems where the teacher gives you busted code to fix, or did you write these?
rent=rent is probably wrong but it will compile etc. its probably this->rent = rent, which highlights the self inflicted misery of using the same variable name twice in one block of code.