Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <conio.h>
  4. #include <iomanip>
  5. #include <fstream>
  6. using namespace std;
  7. class TOVAR
  8. {
  9. int Prof;
  10. void Profit();
  11. public:
  12. char name[15];
  13. double prise;
  14. int supplier;
  15. int deliverGoods;
  16. double PRN;
  17. int Profit_out();
  18. TOVAR();
  19. TOVAR(char p_name[15], int p_prise, int p_supplier, int p_deliverGoods, double p_PRN);
  20. ~TOVAR();
  21. };
  22. TOVAR::TOVAR()
  23. {
  24. strcpy(name, "");prise=0; supplier=0;deliverGoods=0;PRN=0;
  25. }
  26. TOVAR::TOVAR(char p_name[15], int p_prise, int p_supplier, int p_deliverGoods, double p_PRN)
  27. {
  28. strcpy(name, p_name); prise=p_prise; supplier=p_supplier; deliverGoods=p_deliverGoods; PRN=p_PRN;
  29. }
  30. TOVAR::~TOVAR()
  31. {
  32. cout << "DELETE...";
  33. }
  34. void TOVAR::Profit()
  35. {Prof = prise*supplier*deliverGoods*PRN;}
  36. int TOVAR::Profit_out()
  37. {Profit();
  38. return Prof;
  39. }
  40. int main(){
  41. TOVAR Number1;
  42.  
  43. cout<<"Info nomer 1"<<endl;
  44. cout<<"Name: "<<Number1.name<<" "<<" Price- "<<Number1.prise<<" supplier- "<<Number1.supplier<<" deliverGoods- "<<Number1.deliverGoods<<" PRN- "<<Number1.PRN<<endl;
  45.  
  46. TOVAR Number2("Moloko", 100, 10, 5, 1);
  47. cout<<"Info nomer 2"<<endl;
  48. cout<<"Name: "<<Number2.name<<" "<<" Price- "<<Number2.prise<<" supplier- "<<Number2.supplier<<" deliverGoods- "<<Number2.deliverGoods<<" PRN- "<<Number2.PRN<<endl;
  49.  
  50. TOVAR Number3("Xleb", 50, 5, 3, 1);
  51. cout<<"Info nomer 3"<<endl;
  52. cout<<setw(15)<<" Name "<<setw(15)<<" Price "<<setw(15)<<" Profit "<<endl;
  53. cout<<setw(15)<<Number3.name <<setw(15)<<Number3.prise<<setw(15)<<Number3.Profit_out()<<endl;
  54.  
  55. TOVAR Number4("Pechenie", 75, 7, 4, 1);
  56. cout<<"Info nomer 4"<<endl;
  57. cout<<setw(15)<<" Name "<<setw(15)<<" Price "<<setw(15)<<" Profit "<<endl;
  58. cout<<setw(15)<<Number4.name <<setw(15)<<Number4.prise<<setw(15)<<Number4.Profit_out()<<endl;
  59.  
  60. TOVAR Number5("Kefir", 60, 8, 3, 1);
  61. cout<<"Info nomer 5"<<endl;
  62. cout<<setw(15)<<" Name "<<setw(15)<<" Price "<<setw(15)<<" Profit "<<endl;
  63. cout<<setw(15)<<Number5.name <<setw(15)<<Number5.prise<<setw(15)<<Number5.Profit_out()<<endl;
  64.  
  65. TOVAR mas[5];
  66. char zagl[4][10] = {"name", "prise", "supplier", "PRN"};
  67. const char* name_of_file ="D:/huy.txt";
  68. ifstream fin;
  69. fin.open(name_of_file);
  70.  
  71. if(!fin.is_open())
  72. {
  73. cout << endl;
  74. cout << endl;
  75. cout << "-----------------------------Can't open file!!!-----------------------------" << endl;
  76. }
  77. else
  78. {
  79. for(int i=0;i<5;i++)
  80. {
  81. fin >> mas[i].name;
  82. fin >> mas[i].prise;
  83. fin >> mas[i].supplier;
  84. fin >> mas[i].PRN;
  85. }
  86. if(!fin.good())
  87. {
  88. cout << endl;
  89. cout << endl;
  90. cout << "--------------------------FILE HAS BEEN OPENED!-----------------------------" << endl; }
  91. fin.close();
  92. }
  93.  
  94. for (int i=0; i<4; i++) cout << setw(15)<<zagl[i];
  95. cout << endl; cout << endl;
  96. for(int i=0;i<5;i++)
  97. {
  98. cout << setw(15)<< mas[i].name;
  99. cout << setw(15)<< mas[i].prise;
  100. cout << setw(15)<< mas[i].supplier;
  101. cout << setw(15) << mas[i].Profit_out();
  102. cout << endl;
  103. }
  104.  
  105. TOVAR mas_2[5]={ TOVAR ("Moloko", 100, 10, 5, 1), TOVAR ("Xleb", 50, 5, 3, 1), TOVAR ("Pechenie", 75, 7, 4, 1), TOVAR ("Kefir", 60, 8, 3, 1), };
  106. cout << endl;
  107. cout << endl;
  108. cout << setw(50)<<"----------------------------------------------------------------------------";
  109. cout << endl;
  110. cout << endl;
  111. char zagl2[4][10] = {"name", "prise", "supplier", "PRN"};
  112.  
  113. for (int i=0; i<4; i++) cout << setw(15)<< zagl2[i];
  114. cout << endl;
  115. cout << endl;
  116.  
  117. for(int i=0;i<5;i++)
  118. {
  119. cout << setw(15)<< mas[i].name;
  120. cout << setw(15)<< mas[i].prise;
  121. cout << setw(15)<< mas[i].supplier;
  122. cout << setw(15) << mas[i].PRN;
  123. cout << endl;}
  124. return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement