Homework trouble. Can't get my programs to work

can someone help me fix this. Not sure what to do here. I have to fix all four and can't get any of them to work.

number 1
#include<iostream>
class Worker
{
private:
int idNum;
char lastName[20];
char firstName[20];
double salary;
void setIdNum(int id);
void setLastName(char last);
void setFirstName(char first);
void setSalary(double payRate);
void displayWorker();
};

void Worker::setIdNum(int id)
{
if(id< 0 || id > 999)
idNum = 0;
else
idNum = id;
}
void setLastName(char last)
{
strcpy(lastName,last);
}
void Worker::setFirstName(char first)
{
strcpy(firstName,first);
}
void setSalary(double payRate)
{
if (payRate <= 5.75 || payRate > 99.99)
salary = 5.75;
else
salary = payRate;
}

void Worker::displayWorker()
{
cout<<"ID #"<<idNum<<" Name: "<<firstName<<" "<<lastName
<<" Salary: $"<<salary<<endl;
}


void main()
{
Worker aWorker;
aWorker.setIdNum(333);
aWorker.setLastName("Vasquez");
aWorker.setFirstName("Juan");
aWorker.setSalary(15.65);
aWorker.displayWorker();
system("pause");
}






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;
}

void UsedCar::displayUsedCar()
{
cout<<"ID #"<<vehicleID<<" Price: $"<<price<<endl;
cout<<"miles "<<miles<<endl;
}


void main()
{
UsedCar aCar;
aCar.setVehicleID();
aCar.setPrice();
aCar.setYear();
aCar.setMiles();
aCar.displayUsedCar();
system ("pause");
}







number 3
// Debug 5-3
#include<iostream.>
class RaceHorse
{
private:
char name[20];
int age;
double winnings;
static double stableWinnings;
public:
void setRaceHorseData(char raceHorseName[], int raceHorseAge, double raceHorseWinnings);
void showRaceHorse();
};
static double RaceHorse::stableWinnings;

void RaceHorse::setRaceHorseData()
{
strcpy(name, raceHorseName);
age = raceHorseAge;
winnings = raceHorseWinnings;
stableWinnings += winnings;
}
RaceHorse::showRaceHorse()
{
cout<<"RaceHorse: "<<name<<" has won $"<<winnings<<endl;
cout<<"Total stable winnings are $"<<stableWinnings<<endl;
}

void main()
{
RaceHorse stable[3];
int x;
stable[0].setRaceHorseData("Secretariat", 25, 32000);
stable[1].setRaceHorseData("Old Bones", 30, 15000);
stable[2].setRaceHorseData("Citation", 5, 3500);
for(x = 0; x < 3; ++x)
stable[x].showRaceHorse();
system("pause");
}








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.

Last edited on
Topic archived. No new replies allowed.