Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <iomanip>
- using namespace std;
- class tire
- {
- protected:
- char *make;
- double cost;
- double price;
- int size;
- public:
- tire(){};
- tire(char *mk, double cst = 125.0, int sz = 2356018);
- ~tire(){delete [] make;};
- void set_price(void) {price = cost*1.06;}
- double get_price(void) {return price;}
- char * get_make(void) {return make;}
- int get_size(void) {return size;}
- };
- tire::tire(char *mk, double cst, int sz) : size(sz)
- {
- make = new char[strlen(mk)+1];
- strcpy(make, mk);
- cost = cst;
- }
- ostream& operator<< (ostream& os, tire& t)
- {
- os << t.get_make() << " tire size " << setw(10) << t.get_size() << ", price is $" << t.get_price() << endl;
- return os;
- }
- class winter_tire: public tire
- {
- private:
- double mounting_cost;
- public:
- winter_tire(){};
- winter_tire(char *mk, int sz, double cst = 165.00, double mntg_cst = 26.00) : tire(mk, sz, cst), mounting_cost(mntg_cst){}
- virtual void set_price(void) {price = mounting_cost * 1.04;}
- friend ostream& operator<< (ostream& os, winter_tire& t)
- {
- os << t.get_make() << " tire size " << t.get_size() << ", price is $" << t.get_price() << endl;
- return os;
- }
- };
- main()
- {
- tire t1("Goodyear", 125.00, 2555516);;
- tire t2("Bridgestone", 145.00);
- winter_tire w_t1("Michelin", 2605016, 214.00);
- tire *p;
- cout << "CPS311 2014 A4 *LastName*, FirstName, *Khalifa*, Wiz, *Dicky*, Lil" << endl;
- cout.setf(ios::fixed);
- cout.precision(2);
- p = &t1;
- p->set_price();
- cout << endl << t1 << endl;
- p = &t2;
- p->set_price();
- cout << t2 << endl;
- p = &w_t1;
- p->set_price();
- cout << w_t1 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment