Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////////////
- //////////////////////////Anthony Averette C++ Final////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////`
- #include <cstdlib>
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- //Declaring variables
- int length;
- int ctr;
- //Declaring functions
- void InputData();
- void OutputData();
- //Declaring Data Type class
- class CarData4
- {
- //Making things private
- private:
- string pNumber, firstName, lastName, mke, mod;
- int mile, yr;
- //Making Things Public
- public:
- //Public Functions
- int GetMileage(){return mile;}
- string GetPhoneNumber(){return pNumber;}
- string GetFirstName(){ return firstName;}
- int GetYear(){ return yr;}
- string GetLastName(){ return lastName;}
- string GetMake(){ return mke;}
- string GetModel(){ return mod;}
- void OutputData(CarData4 car[], int length);
- void SetMake(string make){mke=make;}
- void SetModel(string model){mod=model;}
- void SetYear(int year){ yr=year;}
- void SetPhoneNumber(string phoneNumber){ pNumber=phoneNumber;}
- void SetLastName(string lName){ lastName=lName;}
- void SetFirstName(string fName){ firstName = fName;}
- void SetMileage(int mileage){ mile=mileage;}
- };
- //The main program
- int main()
- {
- //Declare Variables
- string phoneNumber, fName, lName, make, model;
- int mileage, year;
- char again=true;
- CarData4 outPut;
- //opening the file to write to it
- ofstream Car_Data;
- Car_Data.open ("CarData.txt");
- //Asking for how many vehicles will be input
- cout<<"How many cars would you like to input?(0 to exit) ";
- cin>>length;
- //Declaring The car array variable and car data type
- CarData4 car[length];
- //If statement to see if you want to continue
- if (length >= 1)
- {
- //For loop for the Information
- for( ctr= 0; ctr < length;ctr ++)
- {
- cin.ignore();
- //Data input for cars
- cout<< "Input owner's first name: ";
- getline(cin,fName);
- car[ctr].SetFirstName(fName);
- cout<< "Input owner's last name: ";
- getline(cin,lName);
- car[ctr].SetLastName(lName);
- cout<< "Input the cars Year(1910-2014): ";
- cin>>year;
- car[ctr].SetYear(year);
- do
- {
- //If Statement to see if the year is valid
- if ( year < 1910 || year > 2014 )
- {
- cout<< "Inalivd Input. So lets try this again.\n";
- cout<< "Input the cars Year(1910-2014): ";
- cin>>year;
- car[ctr].SetYear(year);
- if ( year < 1910 || year > 2014 )
- again=false;
- else
- again=true;
- }
- else
- again=false;
- }
- while (again);
- cin.ignore();
- cout<< "Input the owners phone number. ex:(xxx)xxx-xxxx: ";
- getline(cin,phoneNumber);
- car[ctr].SetPhoneNumber(phoneNumber);
- cout<< "Input cars mileage: ";
- cin>>mileage;
- car[ctr].SetMileage(mileage);
- cin.ignore();
- cout<< "Input cars model: ";
- getline(cin,model);
- car[ctr].SetModel(model);
- cout<< "Input the cars Make: ";
- getline(cin,make);
- car[ctr].SetMake(make);
- cout<<"\n";
- }
- for( ctr= 0; ctr <length;ctr ++)
- {
- Car_Data<<"\nInformation for Member: "<< ctr+1<<".\n"
- <<"First Name: "<<car[ctr].GetFirstName()<<"\nLast Name: "
- <<car[ctr].GetLastName()<<"\nPhone Number: "<<
- car[ctr].GetPhoneNumber()<<"\nModel: "<<car[ctr].GetModel()
- <<"\nMake: "<<car[ctr].GetMake()<<"\nYear: "<<
- car[ctr].GetYear();
- }
- //Call to function for outputing info
- outPut.OutputData(car,length);
- }
- else
- {
- Car_Data.close();
- }
- //Closing out the file
- Car_Data.close();
- system("PAUSE");
- return 0;
- }
- //Function for OutputData
- void CarData4::OutputData(CarData4 car[],int length)
- {
- for( ctr= 0; ctr <length;ctr ++)
- {
- cout<<"\nInformation for Member: "<< ctr+1<<".\n"
- <<"First Name: "<<car[ctr].GetFirstName()<<"\nLast Name: "
- <<car[ctr].GetLastName()<<"\nPhone Number: "<<
- car[ctr].GetPhoneNumber()<<"\nModel: "<<car[ctr].GetModel()
- <<"\nMake: "<<car[ctr].GetMake()<<"\nYear: "<<
- car[ctr].GetYear()<<endl;
- }
- }
- //Function InputData
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement