Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Coding in C++ This is the assignment. I am also uploading my written code that I have already. I am struggling with figuring out how

Coding in C++

This is the assignment. I am also uploading my written code that I have already. I am struggling with figuring out how to only show the available cars in option 2 and 5. I am also struggling with how to sort them like in the example with [0]: [1]: etc.

Any help would be appreciated

MY CODE HERE:

image text in transcribed

#include

#include

using namespace std;

void copy (char a[10] , char b[10])

{

for (int i = 0; i

a[i] = b[i];

}

struct car_types //the structure of the car variables

{

int year; //the year is an int variable

char make[10]; //char character array of 10 for make of car

char model[10]; //char character array of 10 for model of car

float price; //float variable for price because dealing with decimals

bool available; //true or false for availability

};

void sort_cars(struct car_types data[],int n) //function for sorting the cars by the data from the input file using the structure of the car_types

{

struct car_types temp;

for (int i = 0; i

{

for (int j =i+1; j

{

if (data[i].price > data[j].price)

{

temp.year = data[i].year;

copy(temp.make,data[i].make);

copy(temp.model,data[i].model);

temp.price = data[i].price;

temp.available = data[i].available;

data[i].year = data[j].year;

copy(data[i].make,data[j].make);

copy(data[i].model,data[j].model);

data[i].price = data[j].price;

data[i].available = data[j].available;

data[j].year = temp.year;

copy(data[j].make,temp.make);

copy(data[j].model,temp.model);

data[j].price = temp.price;

data[j].available = temp.available;

}

}

}

}

void printing_to_terminal(struct car_types data[],int n) //function that prints the options to the terminal

{

for (int i = 0; i

{

cout

if (data[i].available == 0) //the if/else statements that see if the car is avaiable or not, if it sees that the data has an ending with a "0" it will return false.Else it returns true

cout

else

cout

}

}

void print_output(struct car_types data[],int n, int num)

{

for (int i = 0; i

{

if (data[i].available == 1)

{

cout

}

}

}

void input_filename(struct car_types data[])

{

char filename[20];

ifstream fin;

char avail[7];

cout

cin >> filename;

fin.open("Cars.txt");

int count = 0;

while (fin >> data[count].year >> data[count].make >> data[count].model >> data[count].price >> avail)

{

if (avail[0] == 'f')

data[count].available = false;

else

data[count].available = true;

count++;

}

}

void output_file(struct car_types data[], int n)

{

char filename[20];

ofstream fout;

cout

cin >> filename;

fout.open(filename);

int count = 0;

for (int i = 0; i

{

fout

if (data[i].available == false)

{

fout

}

else

{

fout

}

}

}

void number_of_days(struct car_types data[],int n)

{

int num_days;

sort_cars(data,5);

cout

cin >> num_days;

print_output(data,n,num_days);

}

void rent_prices(struct car_types data[], int n)

{

int index;

int num;

cout

cin >> index >> num;

if (data[index-1].available == true)

{

data[index-1].available = false;

cout

}

else

{

cout

}

}

int main()

{

struct car_types data[5];

int choice;

do

{

cout

cout

cout

cout

cout

cout

cout

cout

cin >> choice;

switch (choice)

{

case 1: input_filename(data);

break;

case 2: printing_to_terminal(data, 5);

break;

case 3: output_file(data,5);

break;

case 4: sort_cars(data,5);

break;

case 5: number_of_days(data,5);

break;

case 6: rent_prices(data,5);

break;

}

}

while (choice != 7);

return 0;

}

Sample Output for menu option 2 (before sorting the array by ascending price): 0: 2014 Toyota Tacoma, $115.12 per day, Available: false ]:2015 Ford Fusion, $90.89 per day, Available: true 21: 2009 Dodge Neon, $45.25 per day, Available: false 13p 2015 Ford F150 , $112.83 per day, Available true l: 201 Subaru Outback, $71.27 per day, Available: true Sample Output for menu option 5 (for 2 days of renting, only showing available ones, and with the array already sorted by ascending price, indexes correspond to the sorted array entries): ]: 2016 Subaru Outback, Total Cost: $142.54 12]: 2015 Ford Fusion, Total Cost: $181.78 3:2015 Ford F150, Total Cost: $225.66 The completed project should have the following properties: Written, compiled and tested using Linux It must compile successfully using theg+compiler on department machines. Instructions how to remotely connect to departrment machines are included in the Projects folder in WebCampus. The code must be commened and indented properly. Header comments are required on all files and recommended for the rest of the program Descriptions of functions commented properly A one page (minimum) typed sheet documenting your code. This should include the overall purpose of the program, your desiga, problems (if any), and any changes you would make given more time. Turn in: Compressed epp ile and project documentation. Sample Output for menu option 2 (before sorting the array by ascending price): 0: 2014 Toyota Tacoma, $115.12 per day, Available: false ]:2015 Ford Fusion, $90.89 per day, Available: true 21: 2009 Dodge Neon, $45.25 per day, Available: false 13p 2015 Ford F150 , $112.83 per day, Available true l: 201 Subaru Outback, $71.27 per day, Available: true Sample Output for menu option 5 (for 2 days of renting, only showing available ones, and with the array already sorted by ascending price, indexes correspond to the sorted array entries): ]: 2016 Subaru Outback, Total Cost: $142.54 12]: 2015 Ford Fusion, Total Cost: $181.78 3:2015 Ford F150, Total Cost: $225.66 The completed project should have the following properties: Written, compiled and tested using Linux It must compile successfully using theg+compiler on department machines. Instructions how to remotely connect to departrment machines are included in the Projects folder in WebCampus. The code must be commened and indented properly. Header comments are required on all files and recommended for the rest of the program Descriptions of functions commented properly A one page (minimum) typed sheet documenting your code. This should include the overall purpose of the program, your desiga, problems (if any), and any changes you would make given more time. Turn in: Compressed epp ile and project documentation<>

<>

<>

<>

<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

Students also viewed these Databases questions

Question

What do teacher unions say about the subject?

Answered: 1 week ago

Question

6. What information is contained in a payoff table?

Answered: 1 week ago