Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include "car.cpp"
  4. #include <windows.h>
  5. #include "MyList.h"
  6.  
  7. int main()
  8. {
  9. setlocale(LC_ALL, "Russian");
  10.  
  11. BaseCar *MyItem1;
  12.  
  13. MyItem1 = new BaseCar("1123", 0, 1, "12");
  14.  
  15.  
  16.  
  17.  
  18. return 0;
  19. }
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. #include "pch.h"
  37. #include <iostream>
  38. #include <string>
  39.  
  40. using namespace std;
  41.  
  42. class BaseCar {
  43.  
  44. private:
  45. string Name;
  46. int Cost;
  47. double Weight;
  48. string Manufacturer;
  49.  
  50. public:
  51.  
  52. BaseCar(string Name, int Cost, int Weight, string Manufacturer) {
  53. this->Name = Name;
  54. this->Manufacturer = Manufacturer;
  55.  
  56. setCost(Cost);
  57. setWeight(Weight);
  58. }
  59.  
  60. string getName() {
  61. return Name;
  62. }
  63.  
  64. void setName(string Name) {
  65. this->Name = Name;
  66. }
  67.  
  68. int getCost() {
  69. return Cost;
  70. }
  71.  
  72. void setCost(int Cost) {
  73. if(Cost < 0) this->Cost = Cost;
  74. else cout << "Цена для " << Name << " не должна быть меньше 0\n";
  75. }
  76.  
  77. double getWeight() {
  78. return Weight;
  79. }
  80.  
  81. void setWeight(double Weight) {
  82. if (Weight < 0) this->Weight = Weight;
  83. else cout << "Вес для " << Name << " не должна быть меньше 0\n";
  84. }
  85.  
  86. string getManufacturer() {
  87. return Manufacturer;
  88. }
  89.  
  90. void setManufacturer(string Manufacturer) {
  91. this->Manufacturer = Manufacturer;
  92. }
  93. };
  94.  
  95.  
  96. class TypeCar : public BaseCar {
  97.  
  98. private:
  99. string Type;
  100.  
  101. public:
  102. using BaseCar::BaseCar;
  103.  
  104. void setType(string Type) {
  105. if (Type == "Гражданский" || Type == "Военный")
  106. this->Type = Type;
  107. else
  108. cout << "Машины могут быть \"Гражданский\" или \"Военный\" " << endl;
  109. }
  110.  
  111. string getType() {
  112. return Type;
  113. }
  114. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement