Hi All
I am trying to write a class at the minute for a car insurance program (not to be used for insurance but as an assignment)
I have included a bit of my code below.
What i am looking to do is for example when in car type Seat is entered or BMW is entered it gets stored into make but when anything else is entered a message comes up car currently not insured.
I was looking at doing this with if statements or else the case commands but keep gettin errors. Can anyone tell me how to do this.
The simple code is below.
#include <fstream.h>
#include <iostream>
class Car_Details
{
private:
char Make [10];
public:
void CarData (void)
{
cout <<"\nPlease enter Car Make: ";
cin >> Make;
}
void Show_Car(void)
{
cout <<"\nCar Make is: " <<Make;
cout <<endl;
}
};
int main()
{
char NewCar; // To enter another Cars Details
Car_Details Car; // Creating an Object of Car in typr Car_details
fstream carinfo; //Creating a file to save retreieve data from
carinfo.open("cardetails.dat", ios::trunc | ios:ut | ios::in); //trunc overwrites the info previously inputted
do
{
cout << "\nEnter Car details";
Car.CarData();
carinfo.write( (char*)&Car, sizeof(Car) ); //Write to finaldata
cout << "\nDo you want to enter another Cars Details? (Yes or No?) ";
cin >> NewCar;
}
while (NewCar == 'yes' || NewCar == 'YES' || NewCar == 'Yes' ||NewCar == 'Y' || NewCar == 'y'); //enter a new client if question is answered to yes
carinfo.seekg(0);
carinfo.read( (char*)&Car, sizeof(Car) );
while (!carinfo.eof()) //Quit on End of File
{
cout << "\nCar Details";
Car.Show_Car();
carinfo.read( (char*)&Car, sizeof(Car) ); //Read from file
}
return(0);
}
Any help greatly appricated
I am trying to write a class at the minute for a car insurance program (not to be used for insurance but as an assignment)
I have included a bit of my code below.
What i am looking to do is for example when in car type Seat is entered or BMW is entered it gets stored into make but when anything else is entered a message comes up car currently not insured.
I was looking at doing this with if statements or else the case commands but keep gettin errors. Can anyone tell me how to do this.
The simple code is below.
#include <fstream.h>
#include <iostream>
class Car_Details
{
private:
char Make [10];
public:
void CarData (void)
{
cout <<"\nPlease enter Car Make: ";
cin >> Make;
}
void Show_Car(void)
{
cout <<"\nCar Make is: " <<Make;
cout <<endl;
}
};
int main()
{
char NewCar; // To enter another Cars Details
Car_Details Car; // Creating an Object of Car in typr Car_details
fstream carinfo; //Creating a file to save retreieve data from
carinfo.open("cardetails.dat", ios::trunc | ios:ut | ios::in); //trunc overwrites the info previously inputted
do
{
cout << "\nEnter Car details";
Car.CarData();
carinfo.write( (char*)&Car, sizeof(Car) ); //Write to finaldata
cout << "\nDo you want to enter another Cars Details? (Yes or No?) ";
cin >> NewCar;
}
while (NewCar == 'yes' || NewCar == 'YES' || NewCar == 'Yes' ||NewCar == 'Y' || NewCar == 'y'); //enter a new client if question is answered to yes
carinfo.seekg(0);
carinfo.read( (char*)&Car, sizeof(Car) );
while (!carinfo.eof()) //Quit on End of File
{
cout << "\nCar Details";
Car.Show_Car();
carinfo.read( (char*)&Car, sizeof(Car) ); //Read from file
}
return(0);
}
Any help greatly appricated