Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.10 KB | None | 0 0
  1. // Strukturos 1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "iostream"
  6. #include "iomanip"
  7. #include "cstdlib"
  8. #include "string"
  9. #include "fstream"
  10. #include "cstring"
  11.  
  12. using namespace std;
  13.  
  14. struct Cars {
  15. int number; // cars number in the list
  16. string LicenzePlate; // cars licenze plate number
  17. string Model; // car model
  18. int Year; // year car was made
  19. string Color; // color
  20. string FuelType; // fuel type
  21. int Power; // car power in kw
  22. int FuelUsageC; // fuel usage in town
  23. int FuelUsageOC; // fuel usage outside of town
  24. string Chasy; //chasy type
  25. };
  26.  
  27. Cars A[100] = { 0 };
  28.  
  29. void read();
  30. void colorselected();
  31. void FuelPrice();
  32. void Oldcars();
  33. void AddingCars();
  34. void Sorting();
  35. void Print();
  36. void MainMenu();
  37.  
  38. string name = "Read.txt";
  39. string color;
  40. string line;
  41. int NoOfCars;
  42. bool PrintFuel = false;
  43.  
  44. int main() {
  45.  
  46. cout << ("LD 1") << endl;
  47. cout << ("IF160016") << endl;
  48. cout << ("Mindaugas Jurgelenas") << endl;
  49.  
  50. read();
  51. MainMenu();
  52. system("pause");
  53. return 0;
  54. }
  55.  
  56. void MainMenu() {
  57. //constantly getting double menu in console?
  58. int selection;
  59. cout << ("================ MENU ===================") << endl;
  60. cout << ("Search car by color: 1") << endl;
  61. cout << ("Car Removing from the list: 2") << endl;
  62. cout << ("Car Adding to the list: 3") << endl;
  63. cout << ("Sorting list of cars: 4") << endl;
  64. cout << ("Fuel price calculation: 5") << endl;
  65. cout << ("Exit: 0") << endl;
  66. cin >> selection;
  67.  
  68. if (selection == 1)
  69. colorselected();
  70. else if (selection == 2)
  71. Oldcars();
  72. else if (selection == 3)
  73. AddingCars();
  74. else if (selection == 4)
  75. Sorting();
  76. else if (selection == 5)
  77. FuelPrice();
  78. else
  79. return;
  80. }
  81.  
  82. void read() {
  83.  
  84. cout << ("Enter file name: ");
  85. cin >> name;
  86. ifstream file(name);
  87.  
  88. if (!file) {
  89. cout << ("Error while openining file!") << endl;
  90. system("pause");
  91. }
  92. else {
  93. cout << ("Reading...") << endl;
  94. int i = 0;
  95. while (!file.eof()) {
  96. file >> A[i].number;
  97. file >> A[i].LicenzePlate;
  98. file >> A[i].Model;
  99. file >> A[i].Year;
  100. file >> A[i].Color;
  101. file >> A[i].FuelType;
  102. file >> A[i].Power;
  103. file >> A[i].FuelUsageC;
  104. file >> A[i].FuelUsageOC;
  105. file >> A[i].Chasy;
  106. i++;
  107. }
  108. NoOfCars = i;
  109. cout << ("NoOfCars: ") << NoOfCars << endl;
  110. }
  111. file.close();
  112. cout << ("Reading finnished!") << endl;
  113. Print();
  114. }
  115.  
  116. void colorselected() {
  117.  
  118. cout << endl;
  119. cout << ("Enter color of car your looking for: ");
  120. cin >> color;
  121.  
  122. for (int i = 0; i < NoOfCars; i++) {
  123. if (color == A[i].Color) {
  124. cout << "=========== NAUJA EILUTE ================\n";
  125. cout << "Eil.nr --------- " << A[i].number << endl;
  126. cout << " Valstybinis numeris: " << A[i].LicenzePlate << endl;
  127. cout << " Automobilio marke: " << A[i].Model << endl;
  128. cout << " Pagaminimo metai: " << A[i].Year << endl;
  129. cout << " Automobilio spalva: " << A[i].Color << endl;
  130. cout << " Kuro tipas: " << A[i].FuelType << endl;
  131. cout << " Automobilio galia: " << A[i].Power << endl;
  132. cout << " Kuro sanaudos mieste: " << A[i].FuelUsageC << endl;
  133. cout << " Kuro sanaudos uzmiestyje: " << A[i].FuelUsageOC << endl;
  134. cout << " Kebulo tipas: " << A[i].Chasy << endl;
  135. }
  136. }
  137. MainMenu();
  138. }
  139.  
  140. float Diesel;
  141. float Gasoline;
  142. float Gas;
  143. float Electricity;
  144.  
  145. void FuelPrice() {
  146. cout << endl;
  147. cout << ("Enter price for 1 litre of diesel: ");
  148. cin >> Diesel;
  149. cout << ("Enter price for 1 litre of gasoline: ");
  150. cin >> Gasoline;
  151. cout << ("Enter price for 1 kubik litre of gas: ");
  152. cin >> Gas;
  153. cout << ("Enter price for 1 kw/h of electicity: ");
  154. cin >> Electricity;
  155.  
  156. PrintFuel = true;
  157. Print();
  158. }
  159.  
  160. void Oldcars() {
  161. int currentyear;
  162. cout << "kokie dabar metai ?" << endl;
  163. cin >> currentyear;
  164.  
  165. for (int i = 0; i < NoOfCars; i++) {
  166. if ((currentyear - A[i].Year) >= 15) {
  167. for (int j = i; j < NoOfCars-1; j++) {
  168. A[j] = A[j + 1];
  169. }
  170. i--;
  171. NoOfCars--;
  172. }
  173. }
  174. //for some reasong this doesn't work...
  175. for (int i = 0; i < NoOfCars; i++) {
  176. cout << i << endl;
  177. A[i].number == i++;
  178. }
  179.  
  180. Print();
  181. }
  182.  
  183. void AddingCars() {
  184. cout << endl;
  185. A[NoOfCars].number = NoOfCars + 1;
  186. cout << "Iveskite informacija apie automobili:\n";
  187. cout << "Automobilio numeriai: ";
  188. cin >> A[NoOfCars].LicenzePlate;
  189. cout << "Automobilio marke: ";
  190. cin >> A[NoOfCars].Model;
  191. cout << "Pagaminimo metai: ";
  192. cin >> A[NoOfCars].Year;
  193. cout << "Automobilio spalva: ";
  194. cin >> A[NoOfCars].Color;
  195. cout << "Kuro tipas: ";
  196. cin >> A[NoOfCars].FuelType;
  197. cout << "Variklio galingumas (kW): ";
  198. cin >> A[NoOfCars].Power;
  199. cout << "Kuro sanaudos mieste: ";
  200. cin >> A[NoOfCars].FuelUsageC;
  201. cout << "Kuro sanaudos uzmiestyje: ";
  202. cin >> A[NoOfCars].FuelUsageOC;
  203. cout << "Kebulo tipas: ";
  204. cin >> A[NoOfCars].Chasy;
  205.  
  206. NoOfCars++;
  207.  
  208. Print();
  209. }
  210.  
  211. void Sorting() {
  212. Cars maximum;
  213. for (int i = 0; i < NoOfCars; i++) {
  214. for (int j = 0; j < NoOfCars; j++) {
  215. if (A[j].Year < A[i].Year) {
  216. maximum = A[j];
  217. A[j] = A[i];
  218. A[i] = maximum;
  219. }
  220. }
  221. }
  222. Print();
  223. }
  224.  
  225. void Print() {
  226.  
  227. system("cls");
  228. for (int i = 0; i < NoOfCars; i++) {
  229.  
  230. cout << endl;
  231. cout << "=========== NAUJA EILUTE ================\n";
  232. cout << "Eil.nr --------- " << A[i].number << endl;
  233. cout << " Valstybinis numeris: " << A[i].LicenzePlate << endl;
  234. cout << " Automobilio marke: " << A[i].Model << endl;
  235. cout << " Pagaminimo metai: " << A[i].Year << endl;
  236. cout << " Automobilio spalva: " << A[i].Color << endl;
  237. cout << " Kuro tipas: " << A[i].FuelType << endl;
  238. cout << " Automobilio galia: " << A[i].Power << endl;
  239. cout << " Kuro sanaudos mieste: " << A[i].FuelUsageC << endl;
  240. cout << " Kuro sanaudos uzmiestyje: " << A[i].FuelUsageOC << endl;
  241. cout << " Kebulo tipas: " << A[i].Chasy << endl;
  242. }
  243. if (PrintFuel == true) {
  244. PrintFuel = false;
  245. for (int i = 0; i < NoOfCars; i++) {
  246.  
  247. if (A[i].FuelType == "benzinas") {
  248.  
  249. cout << "=========== NAUJA EILUTE ================\n";
  250. cout << "Eil.nr --------- " << A[i].number << endl;
  251. cout << " Valstybinis numeris: " << A[i].LicenzePlate << endl;
  252. cout << " Automobilio marke: " << A[i].Model << endl;
  253. cout << " Pagaminimo metai: " << A[i].Year << endl;
  254. cout << " Automobilio spalva: " << A[i].Color << endl;
  255. cout << " Kuro tipas: " << A[i].FuelType << endl;
  256. cout << " Automobilio galia: " << A[i].Power << endl;
  257. cout << " Kuro sanaudos mieste: " << A[i].FuelUsageC << (", Kuro kaina 1000km mieste: ") << A[i].FuelUsageC*Gasoline * 10 << (" eur") << endl;
  258. cout << " Kuro sanaudos uzmiestyje: " << A[i].FuelUsageOC << (", Kuro kaina 1000km uzmiestyje: ") << A[i].FuelUsageOC*Gasoline * 10 << (" eur") << endl;
  259. cout << " Kebulo tipas: " << A[i].Chasy << endl;
  260. }
  261. if (A[i].FuelType == "dyzelinas") {
  262.  
  263. cout << "=========== NAUJA EILUTE ================\n";
  264. cout << "Eil.nr --------- " << A[i].number << endl;
  265. cout << " Valstybinis numeris: " << A[i].LicenzePlate << endl;
  266. cout << " Automobilio marke: " << A[i].Model << endl;
  267. cout << " Pagaminimo metai: " << A[i].Year << endl;
  268. cout << " Automobilio spalva: " << A[i].Color << endl;
  269. cout << " Kuro tipas: " << A[i].FuelType << endl;
  270. cout << " Automobilio galia: " << A[i].Power << endl;
  271. cout << " Kuro sanaudos mieste: " << A[i].FuelUsageC << (", Kuro kaina 1000km mieste: ") << A[i].FuelUsageC*Diesel * 10 << (" eur") << endl;
  272. cout << " Kuro sanaudos uzmiestyje: " << A[i].FuelUsageOC << (", Kuro kaina 1000km uzmiestyje: ") << A[i].FuelUsageOC*Diesel * 10 << (" eur") << endl;
  273. cout << " Kebulo tipas: " << A[i].Chasy << endl;
  274. }
  275. if (A[i].FuelType == "dujos") {
  276.  
  277. cout << "=========== NAUJA EILUTE ================\n";
  278. cout << "Eil.nr --------- " << A[i].number << endl;
  279. cout << " Valstybinis numeris: " << A[i].LicenzePlate << endl;
  280. cout << " Automobilio marke: " << A[i].Model << endl;
  281. cout << " Pagaminimo metai: " << A[i].Year << endl;
  282. cout << " Automobilio spalva: " << A[i].Color << endl;
  283. cout << " Kuro tipas: " << A[i].FuelType << endl;
  284. cout << " Automobilio galia: " << A[i].Power << endl;
  285. cout << " Kuro sanaudos mieste: " << A[i].FuelUsageC << (", Kuro kaina 1000km mieste: ") << A[i].FuelUsageC*Gas * 10 << (" eur") << endl;
  286. cout << " Kuro sanaudos uzmiestyje: " << A[i].FuelUsageOC << (", Kuro kaina 1000km uzmiestyje: ") << A[i].FuelUsageOC*Gas * 10 << (" eur") << endl;
  287. cout << " Kebulo tipas: " << A[i].Chasy << endl;
  288. }
  289. if (A[i].FuelType == "elektra") {
  290.  
  291. cout << "=========== NAUJA EILUTE ================\n";
  292. cout << "Eil.nr --------- " << A[i].number << endl;
  293. cout << " Valstybinis numeris: " << A[i].LicenzePlate << endl;
  294. cout << " Automobilio marke: " << A[i].Model << endl;
  295. cout << " Pagaminimo metai: " << A[i].Year << endl;
  296. cout << " Automobilio spalva: " << A[i].Color << endl;
  297. cout << " Kuro tipas: " << A[i].FuelType << endl;
  298. cout << " Automobilio galia: " << A[i].Power << endl;
  299. cout << " Kuro sanaudos mieste: " << A[i].FuelUsageC << (", Kuro kaina 1000km mieste: ") << A[i].FuelUsageC*Gas * 10 << (" eur") << endl;
  300. cout << " Kuro sanaudos uzmiestyje: " << A[i].FuelUsageOC << (", Kuro kaina 1000km uzmiestyje: ") << A[i].FuelUsageOC*Gas * 10 << (" eur") << endl;
  301. cout << " Kebulo tipas: " << A[i].Chasy << endl;
  302. }
  303. }
  304. }
  305. MainMenu();
  306. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement