SlideShare a Scribd company logo
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
class Car
{
private:
string reportingMark;
int carNumber;
string kind;
bool loaded;
string destination;
public:
Car();
Car(const Car &c);
Car(const string &mark, const int &num, const string
&kd, const bool &ld, const string &dest);
~Car();
friend bool operator==(Car a,Car b);
Car& operator=(const Car & carB);
void output1();
void setUp(const string &mark, const int &num, const
string &kd, const bool &ld, const string &dest);
};
class StringOfCars
{
private:
static const int ARRAY_SIZE=10;
Car *ptr;
int carCount;
public:
StringOfCars();
StringOfCars( const StringOfCars &obj);
~StringOfCars();
void push(Car addCar);
void pop(Car &removeCar);
void output2();
};
void input( StringOfCars & string1);
int main()
{
//test 1
Car car1("SP", 34567, "business", true, "Salt Lake City");
Car car2(car1);
cout<<"********************* TEST 1
***********************"<<endl;
car2.output1();
//test 2
StringOfCars string1;
input(string1);
cout<<"********************* TEST 2
***********************"<<endl;
string1.output2();
//test 3
Car car3;
string1.pop(car3);
cout<<"********************* TEST 3
***********************"<<endl;
car3.output1();
string1.output2();
return 0;
}
Car::Car()
{
reportingMark = " ";
carNumber = 0;
kind = "other";
loaded = false;
destination= "NONE";
}
Car::Car(const Car &c)
{
reportingMark = c.reportingMark;
carNumber = c.carNumber;
kind = c.kind;
loaded = c.loaded;
destination = c.destination;
}
Car::Car(const string &mark, const int &num, const string &kd,
const bool &ld, const string &dest)
{
setUp(mark, num, kd, ld, dest);
}
Car:: ~Car()
{}
void Car::output1()
{
cout<<"=========================================
============================="<< endl;
cout<< "The reportingMark: " << reportingMark << endl;
cout<< "The carNumber: " << carNumber<<endl;
cout<< "Kind: " << kind << endl;
if(loaded=true)
cout<< "Loaded: " << "true" << endl;
else
cout<< "Loaded: " << "false" << endl;
cout<< "Destination: " << destination << endl;
}
void Car::setUp (const string &mark, const int &num, const
string &kd, const bool &ld,const string &dest)
{
reportingMark = mark;
carNumber = num;
kind = kd;
loaded = ld;
destination = dest;
}
Car & Car::operator=(const Car & carB)
{
setUp(carB.reportingMark, carB.carNumber, carB.kind,
carB.loaded, carB.destination);
return * this;
}
StringOfCars::StringOfCars()
{
ptr= new Car[ARRAY_SIZE];
carCount=0;
}
//copy constructor
StringOfCars::StringOfCars( const StringOfCars &obj)
{
int ARRAY_CARS = ARRAY_SIZE;
ptr= new Car[ARRAY_CARS];
carCount=obj.carCount;
for(int i=0; i<carCount;i++)
{
ptr[i]= obj.ptr[i];
}
}
//destructor
StringOfCars::~StringOfCars()
{
delete ptr;
ptr=0;
}
//output2
void StringOfCars::output2()
{
if(carCount>0)
{
for(int i=0; i<carCount; i++)
{
cout<<"Car Number"<< (i+1)<<endl;
(ptr+i)->output1();
}
}
else
{
cout<<"NO Cars"<<endl;
}
}
void StringOfCars::push(Car addCar)
{
ptr[carCount]=addCar;
carCount++;
}
void StringOfCars::pop (Car &removeCar)
{
removeCar=ptr[carCount-1];
carCount--;
}
//========================================friend
function========================
bool operator==(Car a, Car b)
{
bool x;
if (a.reportingMark == b.reportingMark && a.carNumber ==
b.carNumber)
x= true;
else
x= false;
return x;
}
//==============================================
=========input function===================
void input(StringOfCars & string1 )
{
ifstream inputFile;
string m;
int n;
string k;
string load;
bool l;
string d;
string carType;
inputFile.open("cardata.txt");
if(!inputFile)
{
cout<<"Error, the file cannot be found!";
}
while(inputFile.peek() != EOF)
{
inputFile >> carType >> m >> n >> k >> load;
if(load=="true")
l=true;
else
l=false;
while(inputFile.peek() == ' ')
inputFile.get();
getline(inputFile,d);
Car temp( m, n, k, l, d);
string1.push(temp);
}
inputFile.close();
}
Assignment 5
Use the same format for problem and function headings as
assignment 1. Problem 5.1
Copy the solution from problem 4.2
In this problem we will use inheritance to create two new
classes, both of which will inherit from the class Car
Do not change the StringOfCar class .
You are not using a StringOfCars in this problem, but will need
it later.
You can remove the StringOfCars from the parameter list for
the input function and put it back later,
or keep the StringOfCars parameter, pass a StringOfCars to the
input funcion, and ignore it.
As a preliminary step, create a new global function (that is a
function that is not a member function) named buildCar.
The buildCar function has the five parameters needed for a Car.
When called, it builds an object of type Car by using the Car
constructor that has five parameters.
For testing in this assignment, after building the car object, the
buildCar function calls the output member function for the Car.
Now, modify the input function so it calls the buildCar function
to build the car, rather than building the car in the input
function.
The kind of cars for the three classes will be:
Car: business, maintenance, other
FreightCar: box, tank, flat, otherFreight
PassengerCar: chair, sleeper, otherPassenger
Use an enum to keep the kind, rather than using a string as we
did in previous problems.
In the global area define an enum named Kind, with the
following values in this order:
business, maintenance, other, box, tank, flat, otherFreight,
chair, sleeper, otherPassenger
Also in the global area define an array of const string objects
named KIND_ARRAY.
It will contain strings with the same text as the names of the
values in the enum, in the same order.
Change the Kind field in the Car class so it is: Kind kind;
Adjust the functions to use the enum and KIND_ARRAY.
The output function can use the KIND_ARRAY values to print
the string corresponding to the enum value.
Build a new member function setKind. in the Car::setUpCar
functionm pass it a constant reference to the string provided by
the user.
If the string is not business or maintenance in the Car class, set
the kind to other.
The setKind member function will set the correct Kind.
Change private to protected in the Car class only.
Make two classes that inherit from the Car class: FreightCar
and PassengerCar.
Each class will need a default constructor, a copy constructor,
and a constructor that has five parameters.
Only one more function will be built in each class; all the rest
will be inherited.
No additional member data will be added.
Create setKind functions for the FreightCar and PassengerCar
classes that are similar to the setKind function for the Car class,
but with different values.
The setKind function for the FreightCar class uses only the
values: box, tank, flat, otherFreight
The setKind function for the PassengerCar class uses only the
values: chair, sleeper, otherPassenger
Create two new global function named buildFreightCar and
buildPassengerCar, similar to the buildCar function.
These are used to build a FreightCar or a Passenger car,
respectively.
Revise the main function to call the input function and do
nothing else.
In the input function loop read one line from the file each time
through the loop, look at the Type field in the record and call
the corresponding build function to build that type of car.
Before calling the appropriate build function, print a header
giving the sequence number of the car read, with the number 1
for the first car and incremented for each successive car.
The file for this problem is called cardata5.txt, and must contain
(without headers, of course):
Type order ARR number kind loaded destination
Car car1 CN 819481 maintenance false NONE
Car car2 SLSF 46871 business true Memphis
Car car3 AOK 156 tender true McAlester
FreightCar car4 MKT 123456 tank false Fort Worth
FreightCar car5 MP 98765 box true Saint Louis
FreightCar car6 SP 567890 flat true Chicago
FreightCar car7 GMO 7878 hopper true Mobile
PassengerCar car8 KCS 7893 chair true Kansas City
PassengerCar car9 PAPX 145 sleeper true Tucson
PassengerCar car10 GN 744 combine false
NONEProblem 5.2
Copy the solution from problem 5.1.
In this problem you will change the StringOfCars class so it has
an array of pointers to objects, rather than an array of objects
themselves. This will allow us to have a string of cars that
contains Car, FreightCar, and PassengerCar objects all in the
same string of cars. This works because a pointer of type Car *
can be made to point to Car objects as well as point to the child
FreightCar and PassengerCar objects.
Remove the call to the output member function from the three
build funtions: buildCar, buildFreightCar, and
buildPassengerCar.
Because you have pointers of type Car * that may point to any
one of the three types of objects, there is a problem. The system
does not know what type object will be encountered until
execution time. That means a system is needed so the functions
that are overridden need to have a mechanism to select the
correct version of the function at execution time, rather than
having it fixed at compile time. This is done with the virtual
declaration. To do this make the declaration of the setKind and
the declaration of the ~Car functions virtual in the Car class.
This is only done in the declaration, not the definition of the
function.
This is only done in the parent class, not the children classes.
To change the class StringOfCars, comment out all the code in
the member functions of the StringOfCars class and fix them
one or two at a time in the following order. These are similar to
the previous functions, but changed to allow for the fact that we
are putting pointers to cars in the array.
· Build the default constructor first. Create a default string of
cars in main.
· Build an output function, similar to the old one, but
dereferrencing the pointers.
· Write a push function which adds a car to the string of cars. It
takes a Car by constant reference, allocates space in the heap,
makes a copy of the Car, and puts the pointer to the Car in the
array.
· Write a copy constructor similar to the old one, but it gets
space for each car and copies each one, as well as getting space
for the array.
· omit the pop member function.
Add to the build functions a call to push the objects onto the
string of cars.
Remove the output from the build functions.
Test the copy constructor by making stringOfCars2 in the stack
for main that is a copy of stringOfCars1.
Print stringOfCars2.

More Related Content

Similar to #include iostream#include string#include iomanip#inclu.docx

publicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdf
publicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdfpublicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdf
publicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdf
ANGELMARKETINGJAIPUR
 
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdfFedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
alukkasprince
 
Public class race track {public static void main(string[] args
Public class race track {public static void main(string[] argsPublic class race track {public static void main(string[] args
Public class race track {public static void main(string[] args
YASHU40
 
C# Programming Help
C# Programming HelpC# Programming Help
C# Programming Help
Programming Homeworks Help
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classes
Intro C# Book
 
Oop in java script
Oop in java scriptOop in java script
Oop in java script
Pierre Spring
 
CountryData.cppEDIT THIS ONE#include fstream #include str.pdf
CountryData.cppEDIT THIS ONE#include fstream #include str.pdfCountryData.cppEDIT THIS ONE#include fstream #include str.pdf
CountryData.cppEDIT THIS ONE#include fstream #include str.pdf
Aggarwalelectronic18
 
The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212
Mahmoud Samir Fayed
 
C#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfC#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdf
ajantha11
 
L9
L9L9
L9
lksoo
 
In C#, visual studio, I want no more text boxes added, I have button.pdf
In C#, visual studio, I want no more text boxes added, I have button.pdfIn C#, visual studio, I want no more text boxes added, I have button.pdf
In C#, visual studio, I want no more text boxes added, I have button.pdf
aggarwalenterprisesf
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason Haffey
Ralph Johnson
 
Scala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Scala Self Types by Gregor Heine, Principal Software Engineer at GiltScala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Scala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Gilt Tech Talks
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
stn_tkiller
 
In this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfIn this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdf
ivylinvaydak64229
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
ORM in Django
ORM in DjangoORM in Django
ORM in Django
Hoang Nguyen
 

Similar to #include iostream#include string#include iomanip#inclu.docx (17)

publicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdf
publicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdfpublicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdf
publicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdf
 
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdfFedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
 
Public class race track {public static void main(string[] args
Public class race track {public static void main(string[] argsPublic class race track {public static void main(string[] args
Public class race track {public static void main(string[] args
 
C# Programming Help
C# Programming HelpC# Programming Help
C# Programming Help
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classes
 
Oop in java script
Oop in java scriptOop in java script
Oop in java script
 
CountryData.cppEDIT THIS ONE#include fstream #include str.pdf
CountryData.cppEDIT THIS ONE#include fstream #include str.pdfCountryData.cppEDIT THIS ONE#include fstream #include str.pdf
CountryData.cppEDIT THIS ONE#include fstream #include str.pdf
 
The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212
 
C#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfC#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdf
 
L9
L9L9
L9
 
In C#, visual studio, I want no more text boxes added, I have button.pdf
In C#, visual studio, I want no more text boxes added, I have button.pdfIn C#, visual studio, I want no more text boxes added, I have button.pdf
In C#, visual studio, I want no more text boxes added, I have button.pdf
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason Haffey
 
Scala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Scala Self Types by Gregor Heine, Principal Software Engineer at GiltScala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Scala Self Types by Gregor Heine, Principal Software Engineer at Gilt
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
In this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfIn this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdf
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
ORM in Django
ORM in DjangoORM in Django
ORM in Django
 

More from mayank272369

NEW YORK STATE It is important to identify and develop vario.docx
NEW YORK STATE It is important to identify and develop vario.docxNEW YORK STATE It is important to identify and develop vario.docx
NEW YORK STATE It is important to identify and develop vario.docx
mayank272369
 
Next, offer your perspective on transparency. In Chapter 3 of th.docx
Next, offer your perspective on transparency. In Chapter 3 of th.docxNext, offer your perspective on transparency. In Chapter 3 of th.docx
Next, offer your perspective on transparency. In Chapter 3 of th.docx
mayank272369
 
New research suggests that the m ost effective executives .docx
New research suggests that the m ost effective executives .docxNew research suggests that the m ost effective executives .docx
New research suggests that the m ost effective executives .docx
mayank272369
 
NewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docx
NewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docxNewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docx
NewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docx
mayank272369
 
Negotiation StylesWe negotiate multiple times every day in e.docx
Negotiation StylesWe negotiate multiple times every day in e.docxNegotiation StylesWe negotiate multiple times every day in e.docx
Negotiation StylesWe negotiate multiple times every day in e.docx
mayank272369
 
Neurological SystemThe nervous system is a collection of nerves .docx
Neurological SystemThe nervous system is a collection of nerves .docxNeurological SystemThe nervous system is a collection of nerves .docx
Neurological SystemThe nervous system is a collection of nerves .docx
mayank272369
 
Neuroleadership is an emerging trend in the field of management..docx
Neuroleadership is an emerging trend in the field of management..docxNeuroleadership is an emerging trend in the field of management..docx
Neuroleadership is an emerging trend in the field of management..docx
mayank272369
 
Network security A firewall is a network security device tha.docx
Network security A firewall is a network security device tha.docxNetwork security A firewall is a network security device tha.docx
Network security A firewall is a network security device tha.docx
mayank272369
 
Network Forensics Use the Internet or the Strayer Library to.docx
Network Forensics Use the Internet or the Strayer Library to.docxNetwork Forensics Use the Internet or the Strayer Library to.docx
Network Forensics Use the Internet or the Strayer Library to.docx
mayank272369
 
Negotiation Process in the International ArenaNegotiation is.docx
Negotiation Process in the International ArenaNegotiation is.docxNegotiation Process in the International ArenaNegotiation is.docx
Negotiation Process in the International ArenaNegotiation is.docx
mayank272369
 
Needs to be 150 word min. Perform a scholarly search (using Pu.docx
Needs to be 150 word min. Perform a scholarly search (using Pu.docxNeeds to be 150 word min. Perform a scholarly search (using Pu.docx
Needs to be 150 word min. Perform a scholarly search (using Pu.docx
mayank272369
 
Needing assistance with powerpoint presentation for Sociology in the.docx
Needing assistance with powerpoint presentation for Sociology in the.docxNeeding assistance with powerpoint presentation for Sociology in the.docx
Needing assistance with powerpoint presentation for Sociology in the.docx
mayank272369
 
Need to write essay on 1000 words about Guns and Crimes , in context.docx
Need to write essay on 1000 words about Guns and Crimes , in context.docxNeed to write essay on 1000 words about Guns and Crimes , in context.docx
Need to write essay on 1000 words about Guns and Crimes , in context.docx
mayank272369
 
Need Research Paper related to the course Related topic in the.docx
Need Research Paper related to the course Related topic in the.docxNeed Research Paper related to the course Related topic in the.docx
Need Research Paper related to the course Related topic in the.docx
mayank272369
 
Need it in about 12 hours. There are 3 docx file each one of.docx
Need it in about 12 hours. There are 3 docx file each one of.docxNeed it in about 12 hours. There are 3 docx file each one of.docx
Need it in about 12 hours. There are 3 docx file each one of.docx
mayank272369
 
Need plagiarism very important Select one type of cryptography o.docx
Need plagiarism very important Select one type of cryptography o.docxNeed plagiarism very important Select one type of cryptography o.docx
Need plagiarism very important Select one type of cryptography o.docx
mayank272369
 
Need the below with in 24 hours.Provide 2 references,500 words.docx
Need the below with in 24 hours.Provide 2 references,500 words.docxNeed the below with in 24 hours.Provide 2 references,500 words.docx
Need the below with in 24 hours.Provide 2 references,500 words.docx
mayank272369
 
Need it within 12-14 hours of time.One paragraph with 300 words .docx
Need it within 12-14 hours of time.One paragraph with 300 words .docxNeed it within 12-14 hours of time.One paragraph with 300 words .docx
Need it within 12-14 hours of time.One paragraph with 300 words .docx
mayank272369
 
Need it to be 300 words. Two paragraphs only. What would you co.docx
Need it to be 300 words. Two paragraphs only.  What would you co.docxNeed it to be 300 words. Two paragraphs only.  What would you co.docx
Need it to be 300 words. Two paragraphs only. What would you co.docx
mayank272369
 
Need it for tomorrow morning!!!!For your synthesis essay, yo.docx
Need it for tomorrow morning!!!!For your synthesis essay, yo.docxNeed it for tomorrow morning!!!!For your synthesis essay, yo.docx
Need it for tomorrow morning!!!!For your synthesis essay, yo.docx
mayank272369
 

More from mayank272369 (20)

NEW YORK STATE It is important to identify and develop vario.docx
NEW YORK STATE It is important to identify and develop vario.docxNEW YORK STATE It is important to identify and develop vario.docx
NEW YORK STATE It is important to identify and develop vario.docx
 
Next, offer your perspective on transparency. In Chapter 3 of th.docx
Next, offer your perspective on transparency. In Chapter 3 of th.docxNext, offer your perspective on transparency. In Chapter 3 of th.docx
Next, offer your perspective on transparency. In Chapter 3 of th.docx
 
New research suggests that the m ost effective executives .docx
New research suggests that the m ost effective executives .docxNew research suggests that the m ost effective executives .docx
New research suggests that the m ost effective executives .docx
 
NewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docx
NewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docxNewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docx
NewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docx
 
Negotiation StylesWe negotiate multiple times every day in e.docx
Negotiation StylesWe negotiate multiple times every day in e.docxNegotiation StylesWe negotiate multiple times every day in e.docx
Negotiation StylesWe negotiate multiple times every day in e.docx
 
Neurological SystemThe nervous system is a collection of nerves .docx
Neurological SystemThe nervous system is a collection of nerves .docxNeurological SystemThe nervous system is a collection of nerves .docx
Neurological SystemThe nervous system is a collection of nerves .docx
 
Neuroleadership is an emerging trend in the field of management..docx
Neuroleadership is an emerging trend in the field of management..docxNeuroleadership is an emerging trend in the field of management..docx
Neuroleadership is an emerging trend in the field of management..docx
 
Network security A firewall is a network security device tha.docx
Network security A firewall is a network security device tha.docxNetwork security A firewall is a network security device tha.docx
Network security A firewall is a network security device tha.docx
 
Network Forensics Use the Internet or the Strayer Library to.docx
Network Forensics Use the Internet or the Strayer Library to.docxNetwork Forensics Use the Internet or the Strayer Library to.docx
Network Forensics Use the Internet or the Strayer Library to.docx
 
Negotiation Process in the International ArenaNegotiation is.docx
Negotiation Process in the International ArenaNegotiation is.docxNegotiation Process in the International ArenaNegotiation is.docx
Negotiation Process in the International ArenaNegotiation is.docx
 
Needs to be 150 word min. Perform a scholarly search (using Pu.docx
Needs to be 150 word min. Perform a scholarly search (using Pu.docxNeeds to be 150 word min. Perform a scholarly search (using Pu.docx
Needs to be 150 word min. Perform a scholarly search (using Pu.docx
 
Needing assistance with powerpoint presentation for Sociology in the.docx
Needing assistance with powerpoint presentation for Sociology in the.docxNeeding assistance with powerpoint presentation for Sociology in the.docx
Needing assistance with powerpoint presentation for Sociology in the.docx
 
Need to write essay on 1000 words about Guns and Crimes , in context.docx
Need to write essay on 1000 words about Guns and Crimes , in context.docxNeed to write essay on 1000 words about Guns and Crimes , in context.docx
Need to write essay on 1000 words about Guns and Crimes , in context.docx
 
Need Research Paper related to the course Related topic in the.docx
Need Research Paper related to the course Related topic in the.docxNeed Research Paper related to the course Related topic in the.docx
Need Research Paper related to the course Related topic in the.docx
 
Need it in about 12 hours. There are 3 docx file each one of.docx
Need it in about 12 hours. There are 3 docx file each one of.docxNeed it in about 12 hours. There are 3 docx file each one of.docx
Need it in about 12 hours. There are 3 docx file each one of.docx
 
Need plagiarism very important Select one type of cryptography o.docx
Need plagiarism very important Select one type of cryptography o.docxNeed plagiarism very important Select one type of cryptography o.docx
Need plagiarism very important Select one type of cryptography o.docx
 
Need the below with in 24 hours.Provide 2 references,500 words.docx
Need the below with in 24 hours.Provide 2 references,500 words.docxNeed the below with in 24 hours.Provide 2 references,500 words.docx
Need the below with in 24 hours.Provide 2 references,500 words.docx
 
Need it within 12-14 hours of time.One paragraph with 300 words .docx
Need it within 12-14 hours of time.One paragraph with 300 words .docxNeed it within 12-14 hours of time.One paragraph with 300 words .docx
Need it within 12-14 hours of time.One paragraph with 300 words .docx
 
Need it to be 300 words. Two paragraphs only. What would you co.docx
Need it to be 300 words. Two paragraphs only.  What would you co.docxNeed it to be 300 words. Two paragraphs only.  What would you co.docx
Need it to be 300 words. Two paragraphs only. What would you co.docx
 
Need it for tomorrow morning!!!!For your synthesis essay, yo.docx
Need it for tomorrow morning!!!!For your synthesis essay, yo.docxNeed it for tomorrow morning!!!!For your synthesis essay, yo.docx
Need it for tomorrow morning!!!!For your synthesis essay, yo.docx
 

Recently uploaded

What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Diana Rendina
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 

Recently uploaded (20)

What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 

#include iostream#include string#include iomanip#inclu.docx

  • 1. #include <iostream> #include <string> #include <iomanip> #include <fstream> using namespace std; class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string destination; public: Car(); Car(const Car &c); Car(const string &mark, const int &num, const string &kd, const bool &ld, const string &dest);
  • 2. ~Car(); friend bool operator==(Car a,Car b); Car& operator=(const Car & carB); void output1(); void setUp(const string &mark, const int &num, const string &kd, const bool &ld, const string &dest); }; class StringOfCars { private: static const int ARRAY_SIZE=10; Car *ptr; int carCount; public: StringOfCars();
  • 3. StringOfCars( const StringOfCars &obj); ~StringOfCars(); void push(Car addCar); void pop(Car &removeCar); void output2(); }; void input( StringOfCars & string1); int main() { //test 1 Car car1("SP", 34567, "business", true, "Salt Lake City"); Car car2(car1); cout<<"********************* TEST 1 ***********************"<<endl; car2.output1(); //test 2
  • 4. StringOfCars string1; input(string1); cout<<"********************* TEST 2 ***********************"<<endl; string1.output2(); //test 3 Car car3; string1.pop(car3); cout<<"********************* TEST 3 ***********************"<<endl; car3.output1(); string1.output2(); return 0; } Car::Car()
  • 5. { reportingMark = " "; carNumber = 0; kind = "other"; loaded = false; destination= "NONE"; } Car::Car(const Car &c) { reportingMark = c.reportingMark; carNumber = c.carNumber; kind = c.kind; loaded = c.loaded; destination = c.destination; } Car::Car(const string &mark, const int &num, const string &kd,
  • 6. const bool &ld, const string &dest) { setUp(mark, num, kd, ld, dest); } Car:: ~Car() {} void Car::output1() { cout<<"========================================= ============================="<< endl; cout<< "The reportingMark: " << reportingMark << endl; cout<< "The carNumber: " << carNumber<<endl; cout<< "Kind: " << kind << endl; if(loaded=true) cout<< "Loaded: " << "true" << endl; else cout<< "Loaded: " << "false" << endl;
  • 7. cout<< "Destination: " << destination << endl; } void Car::setUp (const string &mark, const int &num, const string &kd, const bool &ld,const string &dest) { reportingMark = mark; carNumber = num; kind = kd; loaded = ld; destination = dest; } Car & Car::operator=(const Car & carB) { setUp(carB.reportingMark, carB.carNumber, carB.kind, carB.loaded, carB.destination);
  • 8. return * this; } StringOfCars::StringOfCars() { ptr= new Car[ARRAY_SIZE]; carCount=0; } //copy constructor StringOfCars::StringOfCars( const StringOfCars &obj) { int ARRAY_CARS = ARRAY_SIZE; ptr= new Car[ARRAY_CARS]; carCount=obj.carCount; for(int i=0; i<carCount;i++) { ptr[i]= obj.ptr[i]; }
  • 10. } } else { cout<<"NO Cars"<<endl; } } void StringOfCars::push(Car addCar) { ptr[carCount]=addCar; carCount++; } void StringOfCars::pop (Car &removeCar) { removeCar=ptr[carCount-1];
  • 11. carCount--; } //========================================friend function======================== bool operator==(Car a, Car b) { bool x; if (a.reportingMark == b.reportingMark && a.carNumber == b.carNumber) x= true; else x= false; return x; } //============================================== =========input function===================
  • 12. void input(StringOfCars & string1 ) { ifstream inputFile; string m; int n; string k; string load; bool l; string d; string carType; inputFile.open("cardata.txt"); if(!inputFile) { cout<<"Error, the file cannot be found!"; }
  • 13. while(inputFile.peek() != EOF) { inputFile >> carType >> m >> n >> k >> load; if(load=="true") l=true; else l=false; while(inputFile.peek() == ' ') inputFile.get(); getline(inputFile,d); Car temp( m, n, k, l, d); string1.push(temp); } inputFile.close(); } Assignment 5
  • 14. Use the same format for problem and function headings as assignment 1. Problem 5.1 Copy the solution from problem 4.2 In this problem we will use inheritance to create two new classes, both of which will inherit from the class Car Do not change the StringOfCar class . You are not using a StringOfCars in this problem, but will need it later. You can remove the StringOfCars from the parameter list for the input function and put it back later, or keep the StringOfCars parameter, pass a StringOfCars to the input funcion, and ignore it. As a preliminary step, create a new global function (that is a function that is not a member function) named buildCar. The buildCar function has the five parameters needed for a Car. When called, it builds an object of type Car by using the Car constructor that has five parameters. For testing in this assignment, after building the car object, the buildCar function calls the output member function for the Car. Now, modify the input function so it calls the buildCar function to build the car, rather than building the car in the input function. The kind of cars for the three classes will be: Car: business, maintenance, other FreightCar: box, tank, flat, otherFreight PassengerCar: chair, sleeper, otherPassenger Use an enum to keep the kind, rather than using a string as we did in previous problems. In the global area define an enum named Kind, with the following values in this order: business, maintenance, other, box, tank, flat, otherFreight, chair, sleeper, otherPassenger Also in the global area define an array of const string objects named KIND_ARRAY. It will contain strings with the same text as the names of the values in the enum, in the same order.
  • 15. Change the Kind field in the Car class so it is: Kind kind; Adjust the functions to use the enum and KIND_ARRAY. The output function can use the KIND_ARRAY values to print the string corresponding to the enum value. Build a new member function setKind. in the Car::setUpCar functionm pass it a constant reference to the string provided by the user. If the string is not business or maintenance in the Car class, set the kind to other. The setKind member function will set the correct Kind. Change private to protected in the Car class only. Make two classes that inherit from the Car class: FreightCar and PassengerCar. Each class will need a default constructor, a copy constructor, and a constructor that has five parameters. Only one more function will be built in each class; all the rest will be inherited. No additional member data will be added. Create setKind functions for the FreightCar and PassengerCar classes that are similar to the setKind function for the Car class, but with different values. The setKind function for the FreightCar class uses only the values: box, tank, flat, otherFreight The setKind function for the PassengerCar class uses only the values: chair, sleeper, otherPassenger Create two new global function named buildFreightCar and buildPassengerCar, similar to the buildCar function. These are used to build a FreightCar or a Passenger car, respectively. Revise the main function to call the input function and do nothing else. In the input function loop read one line from the file each time through the loop, look at the Type field in the record and call the corresponding build function to build that type of car. Before calling the appropriate build function, print a header giving the sequence number of the car read, with the number 1
  • 16. for the first car and incremented for each successive car. The file for this problem is called cardata5.txt, and must contain (without headers, of course): Type order ARR number kind loaded destination Car car1 CN 819481 maintenance false NONE Car car2 SLSF 46871 business true Memphis Car car3 AOK 156 tender true McAlester FreightCar car4 MKT 123456 tank false Fort Worth FreightCar car5 MP 98765 box true Saint Louis FreightCar car6 SP 567890 flat true Chicago FreightCar car7 GMO 7878 hopper true Mobile PassengerCar car8 KCS 7893 chair true Kansas City PassengerCar car9 PAPX 145 sleeper true Tucson PassengerCar car10 GN 744 combine false NONEProblem 5.2 Copy the solution from problem 5.1. In this problem you will change the StringOfCars class so it has an array of pointers to objects, rather than an array of objects themselves. This will allow us to have a string of cars that contains Car, FreightCar, and PassengerCar objects all in the same string of cars. This works because a pointer of type Car * can be made to point to Car objects as well as point to the child FreightCar and PassengerCar objects. Remove the call to the output member function from the three build funtions: buildCar, buildFreightCar, and buildPassengerCar. Because you have pointers of type Car * that may point to any one of the three types of objects, there is a problem. The system does not know what type object will be encountered until execution time. That means a system is needed so the functions that are overridden need to have a mechanism to select the correct version of the function at execution time, rather than having it fixed at compile time. This is done with the virtual declaration. To do this make the declaration of the setKind and the declaration of the ~Car functions virtual in the Car class.
  • 17. This is only done in the declaration, not the definition of the function. This is only done in the parent class, not the children classes. To change the class StringOfCars, comment out all the code in the member functions of the StringOfCars class and fix them one or two at a time in the following order. These are similar to the previous functions, but changed to allow for the fact that we are putting pointers to cars in the array. · Build the default constructor first. Create a default string of cars in main. · Build an output function, similar to the old one, but dereferrencing the pointers. · Write a push function which adds a car to the string of cars. It takes a Car by constant reference, allocates space in the heap, makes a copy of the Car, and puts the pointer to the Car in the array. · Write a copy constructor similar to the old one, but it gets space for each car and copies each one, as well as getting space for the array. · omit the pop member function. Add to the build functions a call to push the objects onto the string of cars. Remove the output from the build functions. Test the copy constructor by making stringOfCars2 in the stack for main that is a copy of stringOfCars1. Print stringOfCars2.