Ask coding questions

← Back to all posts
Creating a Structure carType using Data in a File
Siyanda00 (0)

In this lab assignment, you will:
▪ Write the pseudocode.
▪ Create a structure (struct).
▪ Define functions.
▪ Manipulate data using struct.
▪ Create an array of struct items.
▪ Sort data using the selection sort algorithm.
▪ Read information from a text file.
▪ Write information to a text file.
▪ Use ofstream and ifstream.
▪ Compile and execute the program.
Description of the Problem
Suppose that data about cars - the make, registration number and mileage for each car
in the form: Renault FYZ112EC 0, Isuzu HBF454GP 13 000, BMW GKX454CA
100 000 - is stored in a file.
For this assignment, we assume that the data is kept in a file, called, vehicles.txt.
Suppose that the vehicles.txt contains data on 20 cars. Now, use a structure carType,
an array of 20 components of type carType and read the car data from the file
vehicles.txt and load it into an array.
Next, your program should output this data about each car to the screen in this form:
Make Registration Number Mileage
Renault : FYZ112EC : 0
Isuzu : HBF454GP : 13000
Your file must have 5 of the 20 cars with the same mileage and these should be the
cars with highest mileage in your file. The program should then go through the file, find
and print the details of the cars with the highest mileage in the file to the screen in the
same form as before:
Make Registration Number Mileage
BMW : GKX454CA : 100000
Finally, the program should sort the car data into increasing order by mileage starting
with the car with the lowest mileage using the selection sort algorithm. When that is
done, the program should then print out this data to the screen and at the same time
send this data to an output file. Again the output should be in the following form:
Make Registration Number Age
Renault : FYZ112EC : 0
Isuzu : HBF454GP : 13000
BMW : GKX454CA : 100000
Your program must contain at least the following functions:
▪ A function to find the cars with highest mileage.
▪ A function to sort the car data in increasing order using selection sort algorithm.
▪ A function to print the make, registration number and mileage for each car in the
file.

Commentshotnewtop
malvoliothegood (148)

Looks to me that you can not use ifstream and ofstream in the repl.it IDE. fstream works: https://repl.it/@malvoliothegood/CarelessConsciousSandbox-1

Siyanda00 (0)

@malvoliothegood yeah that's true ..I need help

malvoliothegood (148)

@Siyanda00
Are you allowed to use fstream?

malvoliothegood (148)

@Siyanda00
Great. Do you know how to do the task?