Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. struct ComputerInfo
  7. {
  8. char computerMark[20], invertarNumber[6];
  9. unsigned int year;
  10. float weight;
  11. };
  12.  
  13. ComputerInfo computerArray[300];
  14.  
  15. ComputerInfo AddComputers(ComputerInfo compterArray[], int counter)
  16. {
  17. cout << "Enter mark of the computer: ";
  18. cin >> computerArray[counter].computerMark;
  19.  
  20. cout << "Enter year of establish: ";
  21. cin>> computerArray[counter].year;
  22.  
  23. while ((computerArray[counter].year < 1973)
  24. || (computerArray[counter].year > 2013))
  25. {
  26. cout << "INVALID YEAR!!!" << endl;
  27.  
  28. cout << "Enter year of establish: ";
  29. cin>> computerArray[counter].year;
  30. }
  31.  
  32. cout << "Enter computer weidth: ";
  33. cin >> computerArray[counter].weight;
  34.  
  35. cout << "Enter computer invertar number(up to six digits): ";
  36. cin >> computerArray[counter].invertarNumber;
  37.  
  38. return computerArray[counter];
  39. }
  40.  
  41. void ShowRecords()
  42. {
  43. int counter = 0;
  44.  
  45. while (computerArray[counter].year != 0)
  46. {
  47. cout << "Mark: " << computerArray[counter].computerMark << endl;
  48. cout << "Year: " << computerArray[counter].year << endl;
  49. cout << "Weidth: " << computerArray[counter].weight << endl;
  50. cout << "Inv. number: " << computerArray[counter].invertarNumber << endl << endl;
  51.  
  52. counter++;
  53. }
  54. }
  55.  
  56. void MoreThanTenYearsOld(ComputerInfo computerArray[])
  57. {
  58. int counter = 0;
  59. float counterOldComputers = 0;
  60. float computerPer = 0;
  61.  
  62. while (computerArray[counter].year == 0)
  63. {
  64. if (computerArray[counter].year <= 2003)
  65. {
  66. counterOldComputers++;
  67. }
  68.  
  69. counter++;
  70. }
  71.  
  72. computerPer = counterOldComputers / 3;
  73.  
  74. cout << endl;
  75. cout << "Percantage of old computers is: " << computerPer << endl;
  76. }
  77.  
  78. int main()
  79. {
  80. int counter = 0;
  81. float computerPer = 0;
  82. char answer = 'y';
  83.  
  84. for (int i = 0; i <= 299; i++)
  85. {
  86. strcpy(computerArray[i].computerMark,"");
  87. }
  88.  
  89. while((answer == 'Y') || (answer == 'y'))
  90. {
  91. computerArray[counter] = AddComputers(computerArray, counter);
  92. cout << endl;
  93. cout << "Do you want to enter more records (Y/N): ";
  94. cin >> answer;
  95. cout << endl;
  96. counter++;
  97. }
  98.  
  99. MoreThanTenYearsOld(computerArray);
  100.  
  101. return 0;
  102. }
  103.  
  104. std::vector<ComputerInfo> computerArray;
  105.  
  106. ComputerInfo c;
  107. // read the data
  108. computerArray.push_back(c);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement