Professor gave me a homework and I coded.
But it does not work!! :q......
I can't tell what to do... There are no errors.
(Please understand my bad English..)
-It is my homework
◆Homework
UML, main(), refer to execution result, make out a code for Car class and CarList class.
◆Demand
● Car class' member variables are private
-maker : name of manufacturing company (char*)
-passengers : maximum passengers' number (int)
-fuelcap : fuel tank's size (int)
-efficiency : fuel efficiency (float)
● default constructor/constructor with variable/copy constructor/destructor of Car class.
-default constructor : allocate 'null' to 'make' and '0' to the rest
-constructor with variable : allocate input parameter to member variable. Also, 'maker' must be allocated after dynamic allocation.(deep copy)
-copy constructor : allocate all member variables of input parameter to own member variables. Also, 'make' must be allocated after dynamic allocation(deep copy)
-destructor : check 'make' is 'null'. If it is not 'null', deallocate dynamic memory.
● printStatus() : Print all member variables.
● Access to member function with accessor function(set, get)
● getRange() : return the car's maximum travel range(fuelcap * efficiency)
● CarList class' member variables are private
● insert() : add parameter to the end of member variable list (member variable list is vector form)
● print() : print all component of member variable list (member variable list is vector form)
-This is my code
Code:#include <iostream> #include <string> #include <vector> using namespace std; class Car { public: Car(char* p_make, int p_passengers, int p_fuelcap, float p_efficiency) { char* maker= NULL; int passengers=0; int fuelcap=0; float efficiency=0; } Car(); Car(const Car&c) { passengers = c.passengers; fuelcap = c.fuelcap; } ~Car() { if(maker!=NULL) delete maker; } void setMake(char* p_make) { maker=p_make; } void setPassengers(int p_passengers) { passengers=p_passengers; } void setFuelcap(int p_fuelcap) { fuelcap=p_fuelcap; } void setEfficiency(float p_efficiency) { efficiency=p_efficiency; } char* getMake() { return maker; } int getPassengers() { return passengers; } int getFuelcap() { return fuelcap; } float getEfficiency() { return efficiency; } void printStatus() { cout<<"Make : "<<getMake()<<"\nPassengers : "<<getPassengers()<<"\nEfficiency : " <<getEfficiency()<<"\nRange : "<<getRange()<<endl<<endl; } private: char* maker; int passengers; int fuelcap; float efficiency; float getRange() { return fuelcap * efficiency; } }; class CarList { public: void insert(Car&c) { list.push_back(c); } void print() { cout<<"Make"<<endl; } private: vector <Car> list; }; int main() { Car chairman("ssangyoung", 5, 70, 8.4f); cout<<"Chairman Specification" << endl; chairman.printStatus(); Car k9; k9.setMake("kia"); k9.setPassengers(5); k9.setEfficiency(70); k9.setEfficiency(9.4f); cout << endl << "K9 Specification" << endl; k9.printStatus(); Car k3(k9); k3.setEfficiency(14.5); cout << endl << "K3 Specification" << endl; k3.printStatus(); cout << endl<< "Efficiency Comparision" << endl; cout <<"Chariman : "<<chairman.getEfficiency() << endl; cout <<"K9 : " <<k9.getEfficiency() <<endl; cout <<"K3 : " <<k3.getEfficiency() <<endl; CarList list; list.insert(chairman); list.insert(k9); list.insert(k3); cout<< endl << "list"<<endl; list.print(); return 0; }
Plz help... I can't fix it.... :q..:q...:q