fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6.  
  7. class CO_chitietmay{
  8. private:
  9. string O_ma;
  10. public:
  11. CO_chitietmay(){
  12. O_ma = "";
  13. }
  14. friend istream& operator >> (istream &is, CO_chitietmay &x){
  15. cout << "Nhap ma chi tiet may: ";
  16. is >> x.O_ma;
  17. fflush(stdin);
  18. return is;
  19. }
  20. friend ostream& operator << (ostream &os, CO_chitietmay x){
  21. os << "Ma chi tiet may la: " << x.O_ma << endl;
  22. return os;
  23. }
  24. };
  25. class C_chitietnho : public CO_chitietmay {
  26. private:
  27. float trongluong;
  28. float giathanh;
  29. public:
  30. C_chitietnho() : CO_chitietmay() {
  31. trongluong = 0;
  32. giathanh = 0;
  33. }
  34. float Getter_trongluong(){
  35. return this->trongluong;
  36. }
  37. float Getter_giathanh(){
  38. return this->giathanh;
  39. }
  40. friend istream& operator >> (istream &is, C_chitietnho &x){
  41. CO_chitietmay *cha = static_cast<CO_chitietmay *>(&x);
  42. is >> *cha;
  43. cout << "Nhap trong luong: ";
  44. is >> x.trongluong;
  45. cout << "Nhap gia thanh : ";
  46. is >> x.giathanh;
  47. return is;
  48. }
  49. friend ostream& operator << (ostream &os, C_chitietnho x){
  50. CO_chitietmay cha = static_cast<CO_chitietmay>(x);
  51. os << cha;
  52. os << "Trong luong: " << x.trongluong << endl;
  53. os << "Gia thanh : " << x.giathanh << endl;
  54. return os;
  55. }
  56. };
  57. class C_chitietphuc{
  58. private:
  59. vector<C_chitietnho> chitietphuc;
  60. public:
  61. friend istream& operator >> (istream &is, C_chitietphuc &x){
  62. bool check = false;
  63. int i = 0 , choose;
  64. do
  65. {
  66. C_chitietnho a;
  67. cout << "Nhap Chi tiet don thu " << i + 1 << endl;
  68. is >> a;
  69. x.chitietphuc.push_back(a);
  70. cout << "Ban muon nhap tiep ko?: ";
  71. is >> choose;
  72. i++;
  73. } while (choose);
  74. return is;
  75. }
  76. friend ostream& operator << (ostream &os, C_chitietphuc x){
  77. for(int i = 0 ; i < x.chitietphuc.size() ; i++){
  78. os << "Chi tiet don thu "<< i + 1 << endl;
  79. os << x.chitietphuc[i] << endl;
  80. }
  81. return os;
  82. }
  83. };
  84. class Machines{
  85. private:
  86. vector <C_chitietnho> danhsachnho; // chi tiet don
  87. vector <C_chitietphuc> danhsachphuc;
  88. float trongluong, giathanh;
  89. public:
  90. Machines(){
  91. trongluong = 0;
  92. giathanh = 0;
  93. }
  94. void Nhap(){
  95. int choose;
  96. int i = 0, j = 0;
  97. do
  98. {
  99. system("cls");
  100. cout << "Cac bo phan che tac ra 1 co may" << endl;
  101. cout << "+1. Nhap chi tiet don. " << endl;
  102. cout << "+2. Nhap chi tiet phuc. "<< endl;
  103. cout << "+3. Thoat" << endl;
  104. cout << "Ban chon: ";
  105. cin >> choose;
  106. switch(choose){
  107. case 1 :
  108. {
  109. cout << "Nhap chi tiet don thu " << i + 1 << endl;
  110. C_chitietnho x;
  111. cin >> x;
  112. danhsachnho.push_back(x);
  113. i++;
  114. break;
  115. }
  116. case 2 :
  117. {
  118. cout << "Nhap chi tiet phuc thu " << j + 1 << endl;
  119. C_chitietphuc x;
  120. cin >> x;
  121. danhsachphuc.push_back(x);
  122. j++;
  123. break;
  124. }
  125. }
  126. } while (choose != 3);
  127. }
  128. void Xuat()
  129. {
  130. cout << "Cau tao cua 1 co may gom: " << danhsachnho.size() << " Chi tiet nho vs : " << danhsachphuc.size() << " Chi tiet phuc"<< endl;
  131. for(int k = 0 ; k < danhsachnho.size() ; k++ ){
  132. cout <<"+Chi tiet don thu "<< k + 1 << endl << danhsachnho[k];
  133. }
  134. cout << "\n---------------------------------------------------------\n";
  135. for(int h = 0 ; h < danhsachphuc.size() ; h++){
  136. cout << "+Chi tiet phuc thu " << h + 1 << endl << danhsachphuc[h];
  137. }
  138. cout << "------------------Ket Thuc------------------------" << endl;
  139. }
  140. float trongluong_comay(){
  141. float Sum_trongluong = 0;
  142. float thietbinoi;
  143. // chi tiet don truoc;
  144. for(int i = 0 ; i < danhsachnho.size() ; i++){
  145. Sum_trongluong += danhsachnho[i].Getter_trongluong();
  146. }
  147. cout << "Thiet bi noi: ";
  148. cin >> thietbinoi;
  149. return Sum_trongluong + 0.1 * thietbinoi;
  150. }
  151. float giathanh_comay(){
  152. float conglaprap;
  153. float Sum_giathanh = 0;
  154. // chi tiet don truoc;
  155. for(int i = 0 ; i < danhsachnho.size() ; i++){
  156. Sum_giathanh += danhsachnho[i].Getter_giathanh();
  157. }
  158. cout << "Cong lap rap: ";
  159. cin >> conglaprap;
  160. return Sum_giathanh + 0.2 * conglaprap;
  161. }
  162. };
  163. int main()
  164. {
  165. Machines a;
  166. a.Nhap();
  167. a.Xuat();
  168. cout << "\nTrong luong cua Machine(Co may): "<< a.trongluong_comay() << endl;
  169. cout << "\nGia thanh cua Machine(Co may) : " << a.giathanh_comay() << endl;
  170. cout << endl;
  171. system("pause");
  172. return 0;
  173. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'std::istream& operator>>(std::istream&, CO_chitietmay&)':
prog.cpp:17:10: error: 'stdin' was not declared in this scope
   fflush(stdin);
          ^
prog.cpp:17:15: error: 'fflush' was not declared in this scope
   fflush(stdin);
               ^
prog.cpp: In member function 'void Machines::Nhap()':
prog.cpp:99:16: error: 'system' was not declared in this scope
    system("cls");
                ^
prog.cpp: In function 'int main()':
prog.cpp:171:16: error: 'system' was not declared in this scope
  system("pause");
                ^
stdout
Standard output is empty