C++ Develop an application that has at least 3 classes that models or simulates
ID: 3838031 • Letter: C
Question
C++
Develop an application that has at least 3 classes that models or simulates driving a car to the gas station to purchase gas and drive home again. Must have two .cpp files and one header.
You should have a least 3 classes and no more than 5 classes. I highly recommend you keep it to 3 classes and keep the project simple.
File I/O required. You must use file operations to either read something in or write something out. I don't care which but you must show that you can do file I/O operations. For example, let's say I write an application to model driving a car to the gas station, paying for the gas, and then pumping gas in my car and driving home. You could write a message to the screen telling the user what's going on during the program and you could send those same messages to a file to prove you can open a file and write to it. Another example: Say you write an application to play a game, you could let the user quit the game before finishing and write out the state of the game to a file. Then the user could start the game application later and the application would check for the existence of a saved-game file and start the game where you left off by opening the file and reading in the game state. (My recommendation, take the easy route and just write some log messages to a file.)
Explanation / Answer
to drive a car to the gas station from home one has to follow the following:
u will have 3 classes which are
1) start class which defines that the car has started from the house which has the following values the start will have thee operations as
a)pumping the gas into the car
b)paying for the gas pumped
c)closing the cap of the car
a)for pumping the gas into the car one has to open the lid of the car for opening the lid the filw operation can be void open(const char *filename, ios::openmode open)here, the first operation of the file shows the location of the file and filename and the second operation shows the mode of the file.ofstream outfile; outfile.open("afile.dat"); these are used to open the file instead of using the cin>> operation we can directly open the file with the open operation
b)for paying for the gas pumped we can use read from a file because we can read the total amount that has to be paid to the gas station for filling gas into the car. we can use myfile(gasreading.txt). the read operaton can be performed by using the detials in the txt file. let us suppose that the txt file is the bill generated. here the bill is given as input to read the pay for the gas.
c)for closing the lid of the car we use the close operation myfile.close(). this file operation is used to close the current file here the current file can be taken as the lid of the car .
2) and the last one can be going back home we can have the return class in which the operations can be close the door of the car and the open operation can also be performed.
here the header file can be iostream which is input output stream that can be used to perform the input operations such as open read.
the output stream is used to perform the operations such as close operation.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.