Advertisement
Guest User

Untitled

a guest
May 30th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. //ClassAuto.cpp
  2. #include <iostream>
  3. #include <sstream>
  4. #include <ctime>
  5. #include <string>
  6. using namespace std;
  7.  
  8. class Auto
  9. {
  10. private:
  11. string hersteller;
  12. int alter;
  13. double neuPreis;
  14. public:
  15. Auto();
  16. Auto(string, int, double);
  17. void read();
  18. string toString();
  19. double gebrauchtPreis();
  20. };
  21. Auto::Auto()
  22. {
  23. hersteller = "BRUMMM";
  24. alter = 10;
  25. neuPreis = 10000;
  26.  
  27. }
  28.  
  29. Auto::Auto(string herst, int alter, double pr)
  30. {
  31.  
  32. hersteller = herst;
  33. this->alter = alter;
  34. neuPreis = pr;
  35. }
  36. void Auto::read(){
  37. cout<<"Hersteller:"<<endl;
  38. cin>>hersteller;
  39. cout<<"Alter:"<<endl;
  40. cin>>alter;
  41. cout<<"Neupreis:"<<endl;
  42. cin>>neuPreis;
  43. }
  44.  
  45. string Auto::toString()
  46. {
  47.  
  48. stringstream s;
  49. s << endl << "Hersteller: " << hersteller << endl << "Alter: " << alter << endl << "Neupreis: " << neuPreis << endl;
  50. return s.str();
  51.  
  52. }
  53.  
  54. double Auto::gebrauchtPreis()
  55. {
  56. return neuPreis/alter;
  57. }
  58. Auto teuerstesAuto(Auto a[], int n)
  59. {
  60. {
  61. double max = a[0].gebrauchtPreis();
  62. Auto maxAuto = a[0];
  63. for (int i = 1;i<n;i++)
  64. {
  65. if (a[i].gebrauchtPreis()>max)
  66. {
  67. max = a[i].gebrauchtPreis();
  68. maxAuto = a[i];
  69. }
  70. }
  71. return maxAuto;
  72. }
  73. }
  74. double kapital(Auto a[], int n)
  75. {
  76. double Capital = 0.0;
  77. int i;
  78. for (int i =0;i<n;i++)
  79. {
  80. Capital = Capital + a[i].gebrauchtPreis();
  81. }
  82.  
  83. return Capital;
  84. }
  85. int main()
  86. {
  87. srand(time(0));
  88. int n;
  89. cin>>n;
  90. Auto *werkstatt = new Auto[n];
  91. for (int i=0;i<n;i++);
  92. {
  93. werkstatt[i].read();
  94. cout <<"CUSTOMER NUMBER: " << i+1 <<endl<<werkstatt[i].tostring()<<endl;
  95. }
  96.  
  97. cout << "Teuerstes Auto: " << teuerstesAuto(werkstatt,n).toString() << endl;
  98. cout << "Kapital :" << kapital(werkstatt,n);
  99.  
  100.  
  101. cout << endl << endl;
  102. system("PAUSE");
  103.  
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement