*update1:
Hi, thanks to everyone so that i was able to finish the c1 problem. But jump in to C2 which is relative to constructor and i am being stuck with it. Can you ex plain for my what is wrong with my code. I am trying to follow instruction. I want to create an object mycar but the complier say that no matching function for call to Car::car. it seems to me somethings are wrong with my constructors.
Copy the solution from problem C1.
Order of functions in the code:
Note that the setup and output functions have been moved to a different location.
Car constructors and destructor within the Car class definition
default constructor
copy constructor
other constructors
destructor
main
Car member functions declared within the Car class but defined later
setup
output
input
Make the following additions and changes:
Build three constructors and a destructor for your Car class:
A default constructor. Build this constructor with only one line of code that calls the setup member function. Set the following values:
reportingMark (an empty string)
carNumber 0
kind other
loaded false
destination NONE
A copy constructor. Build this constructor with only one line of code that calls the setup member function.
A constructor that accepts five parameters. Build this constructor with only one line of code that calls the setup member function.
A destructor that does nothing.
Put a declaration in the Car class for the setup and output functions. (The declaration is just the prototype)
Put the definition of these functions later. (The definition of a function contains the code)
Remove the call to the setup function from the main function.
Remove new and delete from the main function.
Revise the main function to create three Car objects in the stack by using the three constructors:
car1 which uses the values read from the user. Use the same values used to test assignment C1.
car2 which is copied from car1.
car3 which is created with the default constructor.
Problem C1
Order of functions in the code:
Within the Car class:
setup
output
Global functions, outside of the Car class:
main
input
Define a class named: Car
containing the following private data:
reportingMark a string with the AAR reporting mark
carNumber an int
kind a string which could contain "business" "maintenance" or "other"
loaded a bool
destination a string with a destination or the word "NONE"
Note:
A destination is required if the car is loaded.
If it is not loaded the destination may be either a destination or the word "NONE".
Be sure to allow the user the option of entering a destination when the car is not loaded.
Within the class create the following member functions:
setup
Is a member function of the class Car
Takes the five parameters by value: reportingMark, carNumber, kind, loaded, and destination
Puts the data in the object
Has a return type of void
output
Is a member function of the class Car
Has no parameters
Prints the member data in a neat format
Has a return type of void
After the class, create the following global functions:
main
Contains six variables:
a pointer named ptr which points to a Car object
a string named reportingMark to contain two to four characters
an int named carNumber
a string named kind which could contain: "business" "maintenance" or "other"
a bool named loaded
a string named destination containing a destination or the word NONE
Uses new to obtain space for an object of type Car
Calls the input, setup, and output functions
Deletes the space obtained using new
input
Is a global function, not a member of the class
Takes the reportingMark, carNumber, kind, loaded, and destination as reference parameters
Reads the reportingMark, carNumber, kind, loaded, and destination from the user
Has a return type of void
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/*
/*
Phuong Pham
CIS 22B
quarter Fall 2016
Assignment C
Problem C1
Description of problem:
Problem C1
Order of functions in the code:
Within the Car class:
*/
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
class Car
{
string reportingMark;
int Carnumber=0;
string kind="other";
bool loaded=0;
string destination="NONE";
int *ptr;
~Car(); //destructor
public:
void setUp (string, int, string, bool, string);
void outPut();
Car(setUp());
Car(string , int , string , bool , string );
}mycar;
void input (string &reportingMark, int &Carnumber, string &kind, bool &loaded, string &destination);
int main(int argc, const char * argv[])
{
string reportingMark;
int Carnumber;
string kind;
bool loaded;
string destination="NONE";
Car car1,car2,car3;
car2=car1;
car3=Car();
input(reportingMark,Carnumber,kind,loaded,destination);
return 0;
}
void input (string &reportingMark, int &Carnumber, string &kind, bool &loaded, string &destination)
{
cout << "What is your reportingMark: "<< endl;
cin >> reportingMark;
cout << "What is your carNumber"<< endl;
cin >> Carnumber;
cout << "What is your kind of your car?"<<endl;
while (kind != "business")
{
cin >> kind;
if (kind != "business" && kind != "maintenance" && kind!= "other")
{
cout << "Your input is invalid. Please type again "<<endl;
}
else
break;
}
cout << "Is your car loaded: "<<endl;
cout << "If you say yes please type 1. Otherwise please type 0"<<endl;
cin >>loaded;
if (loaded == true)
{
cout << "What is your destination: "<<endl;
cin >> destination;
}
else if (loaded == false)
{
cout << "What is your destination: "<<endl;
cin >>destination;
if(destination == "no")
{
cout <<"Thank you"<<endl;
}
}
}
void Car::setUp( string reportingMark, int Carnumber, string kind, bool loaded, string destination )
{
mycar.reportingMark=reportingMark;
mycar.Carnumber=Carnumber;
mycar.kind=kind;
mycar.loaded=loaded;
mycar.destination=destination;
}
void Car::outPut()
{
cout <<mycar.reportingMark<<endl;
cout <<mycar.Carnumber<<endl;
cout <<mycar.kind<<endl;
cout<<boolalpha<<mycar.loaded<<endl;
cout <<mycar.destination<<endl;
}
Car::~Car()
{}
|