Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ClassAuto.cpp
- #include <iostream>
- #include <sstream>
- #include <ctime>
- #include <string>
- using namespace std;
- class Auto
- {
- private:
- string hersteller;
- int alter;
- double neuPreis;
- public:
- Auto();
- Auto(string, int, double);
- void read();
- string toString();
- double gebrauchtPreis();
- };
- Auto::Auto()
- {
- hersteller = "BRUMMM";
- alter = 10;
- neuPreis = 10000;
- }
- Auto::Auto(string herst, int alter, double pr)
- {
- hersteller = herst;
- this->alter = alter;
- neuPreis = pr;
- }
- void Auto::read(){
- cout<<"Hersteller:"<<endl;
- cin>>hersteller;
- cout<<"Alter:"<<endl;
- cin>>alter;
- cout<<"Neupreis:"<<endl;
- cin>>neuPreis;
- }
- string Auto::toString()
- {
- stringstream s;
- s << endl << "Hersteller: " << hersteller << endl << "Alter: " << alter << endl << "Neupreis: " << neuPreis << endl;
- return s.str();
- }
- double Auto::gebrauchtPreis()
- {
- return neuPreis/alter;
- }
- Auto teuerstesAuto(Auto a[], int n)
- {
- {
- double max = a[0].gebrauchtPreis();
- Auto maxAuto = a[0];
- for (int i = 1;i<n;i++)
- {
- if (a[i].gebrauchtPreis()>max)
- {
- max = a[i].gebrauchtPreis();
- maxAuto = a[i];
- }
- }
- return maxAuto;
- }
- }
- double kapital(Auto a[], int n)
- {
- double Capital = 0.0;
- int i;
- for (int i =0;i<n;i++)
- {
- Capital = Capital + a[i].gebrauchtPreis();
- }
- return Capital;
- }
- int main()
- {
- srand(time(0));
- int n;
- cin>>n;
- Auto *werkstatt = new Auto[n];
- for (int i=0;i<n;i++);
- {
- werkstatt[i].read();
- cout <<"CUSTOMER NUMBER: " << i+1 <<endl<<werkstatt[i].tostring()<<endl;
- }
- cout << "Teuerstes Auto: " << teuerstesAuto(werkstatt,n).toString() << endl;
- cout << "Kapital :" << kapital(werkstatt,n);
- cout << endl << endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement