Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////Anthony Averette C++ Final////////////////////////////
  3. ////////////////////////////////////////////////////////////////////////////////`
  4. #include <cstdlib>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8. using namespace std;
  9.  
  10. //Declaring variables
  11. int length;
  12. int ctr;
  13.  
  14. //Declaring functions
  15. void InputData();
  16. void OutputData();
  17.  
  18. //Declaring Data Type class
  19.  
  20. class CarData4
  21. {
  22.  
  23. //Making things private
  24. private:
  25.  
  26. string pNumber, firstName, lastName, mke, mod;
  27. int mile, yr;
  28.  
  29. //Making Things Public
  30. public:
  31.  
  32. //Public Functions
  33. int GetMileage(){return mile;}
  34. string GetPhoneNumber(){return pNumber;}
  35. string GetFirstName(){ return firstName;}
  36. int GetYear(){ return yr;}
  37. string GetLastName(){ return lastName;}
  38. string GetMake(){ return mke;}
  39. string GetModel(){ return mod;}
  40. void OutputData(CarData4 car[], int length);
  41. void SetMake(string make){mke=make;}
  42. void SetModel(string model){mod=model;}
  43. void SetYear(int year){ yr=year;}
  44. void SetPhoneNumber(string phoneNumber){ pNumber=phoneNumber;}
  45. void SetLastName(string lName){ lastName=lName;}
  46. void SetFirstName(string fName){ firstName = fName;}
  47. void SetMileage(int mileage){ mile=mileage;}
  48. };
  49.  
  50. //The main program
  51. int main()
  52. {
  53. //Declare Variables
  54. string phoneNumber, fName, lName, make, model;
  55. int mileage, year;
  56.  
  57. char again=true;
  58. CarData4 outPut;
  59. //opening the file to write to it
  60. ofstream Car_Data;
  61. Car_Data.open ("CarData.txt");
  62.  
  63. //Asking for how many vehicles will be input
  64. cout<<"How many cars would you like to input?(0 to exit) ";
  65. cin>>length;
  66.  
  67. //Declaring The car array variable and car data type
  68. CarData4 car[length];
  69.  
  70. //If statement to see if you want to continue
  71. if (length >= 1)
  72. {
  73. //For loop for the Information
  74. for( ctr= 0; ctr < length;ctr ++)
  75. {
  76. cin.ignore();
  77. //Data input for cars
  78. cout<< "Input owner's first name: ";
  79. getline(cin,fName);
  80. car[ctr].SetFirstName(fName);
  81.  
  82. cout<< "Input owner's last name: ";
  83. getline(cin,lName);
  84. car[ctr].SetLastName(lName);
  85. cout<< "Input the cars Year(1910-2014): ";
  86. cin>>year;
  87. car[ctr].SetYear(year);
  88. do
  89. {
  90. //If Statement to see if the year is valid
  91. if ( year < 1910 || year > 2014 )
  92. {
  93. cout<< "Inalivd Input. So lets try this again.\n";
  94. cout<< "Input the cars Year(1910-2014): ";
  95. cin>>year;
  96. car[ctr].SetYear(year);
  97. if ( year < 1910 || year > 2014 )
  98. again=false;
  99. else
  100. again=true;
  101. }
  102.  
  103. else
  104. again=false;
  105. }
  106. while (again);
  107. cin.ignore();
  108. cout<< "Input the owners phone number. ex:(xxx)xxx-xxxx: ";
  109. getline(cin,phoneNumber);
  110. car[ctr].SetPhoneNumber(phoneNumber);
  111. cout<< "Input cars mileage: ";
  112. cin>>mileage;
  113. car[ctr].SetMileage(mileage);
  114. cin.ignore();
  115. cout<< "Input cars model: ";
  116. getline(cin,model);
  117. car[ctr].SetModel(model);
  118. cout<< "Input the cars Make: ";
  119. getline(cin,make);
  120. car[ctr].SetMake(make);
  121. cout<<"\n";
  122. }
  123. for( ctr= 0; ctr <length;ctr ++)
  124. {
  125. Car_Data<<"\nInformation for Member: "<< ctr+1<<".\n"
  126. <<"First Name: "<<car[ctr].GetFirstName()<<"\nLast Name: "
  127. <<car[ctr].GetLastName()<<"\nPhone Number: "<<
  128. car[ctr].GetPhoneNumber()<<"\nModel: "<<car[ctr].GetModel()
  129. <<"\nMake: "<<car[ctr].GetMake()<<"\nYear: "<<
  130. car[ctr].GetYear();
  131. }
  132. //Call to function for outputing info
  133. outPut.OutputData(car,length);
  134.  
  135. }
  136. else
  137. {
  138. Car_Data.close();
  139. }
  140. //Closing out the file
  141. Car_Data.close();
  142. system("PAUSE");
  143. return 0;
  144. }
  145.  
  146. //Function for OutputData
  147. void CarData4::OutputData(CarData4 car[],int length)
  148. {
  149. for( ctr= 0; ctr <length;ctr ++)
  150. {
  151. cout<<"\nInformation for Member: "<< ctr+1<<".\n"
  152. <<"First Name: "<<car[ctr].GetFirstName()<<"\nLast Name: "
  153. <<car[ctr].GetLastName()<<"\nPhone Number: "<<
  154. car[ctr].GetPhoneNumber()<<"\nModel: "<<car[ctr].GetModel()
  155. <<"\nMake: "<<car[ctr].GetMake()<<"\nYear: "<<
  156. car[ctr].GetYear()<<endl;
  157. }
  158. }
  159.  
  160. //Function InputData
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement