Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[c++] Help with aligning columns using setw within this code. printed areas(output) are highlighted in bold. external document info at end of code. #include #include

[c++] Help with aligning columns using setw within this code. printed areas(output) are highlighted in bold. external document info at end of code.

#include

#include

#include // for file read

#include

using namespace std;

struct cars //structure

{

string carName; //for name

int year;

string value; //for date of manufature and current value

}e[10];

int main() {

string carName;

int year, n; //nis#cars,

string value;

ifstream myfile("cars.txt");

n = 0;

// check for error

if (myfile.fail())

{

cerr << " Error opening file" << endl;

exit(1);

}

// loop to read car details from file

while (myfile >> carName >> year >> value)

{

e[n].carName = carName;

e[n].year = year;

e[n].value = value;

n++; //count number cars in file

}

cout << "Printing Original Data... " << endl;

for (int i = 0;i

cout << e[i].carName << " " << e[i].year << " " << e[i].value << endl; //print read data

cout << " Sort ascending order with year " << endl;

// sort the data using bubble sort

for (int i = 0;i

for (int j = 0;j

if (e[j].year > e[j + 1].year)

{

// swap cars

cars carTemp = e[j];

e[j] = e[j + 1];

e[j + 1] = carTemp;

}

for (int i = 0;i < n;i++) {

cout << e[i].carName << " " << e[i].year << " " << e[i].value << endl; //print read data

}

cout << " Sort descending order with value " << endl;

// sort the data using bubble sort

for (int i = 0;i

for (int j = 0;j

if (e[j].value < e[j + 1].value)

{

cars carTemp = e[j];

e[j] = e[j + 1];

e[j + 1] = carTemp;

}

for (int i = 0;i

cout << e[i].carName << " " << e[i].year << " " << e[i].value << endl; //print read data

myfile.close();

return 0;

}

Mustang 2006 $6019 Viper 2003 $37899 corvette 1967 $71995 Accord 2002 $3070 Maxima 2017 $20060 Civic 2001 $3381 F150 1998 $4400 Raptor 2010 $22640 Fusion 2011 $6387 Cruise 2016 $6143

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

Database Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions

Question

Understand why customers complain.

Answered: 1 week ago