Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help me print this display in a near aligned colum format, the rest of the code is written but I cant seem to

Can you help me print this display in a near aligned colum format, the rest of the code is written but I cant seem to get this right
#include "library.h"
#include
#include
void display(const College a[], unsigned n){
std::cout << std::left << std::setw(30)<< "Name" << std::setw(10)<< "Cost" << std::setw(15)<< "Acceptance Rate" << std::endl;
for (unsigned i =0; i < n; i++){
std::cout << std::left << std::setw(30)<< a[i].name << std::setw(10)<<"$"<< a[i].cost << std::setw(15);
std::cout << std::fixed << std::setprecision(2)<< a[i].acceptance_rate <<"%"<< std::endl;
}
double total_cost =0;
for (unsigned i =0; i < n; i++){
total_cost += a[i].cost;
}
double average_cost = total_cost / n;
std::cout << "Average cost: $"<< std::fixed << std::setprecision(2)<< average_cost << std::endl;
}
int search(const College a[], unsigned n, std::string name, std::string category){
for (unsigned i =0; i < n; i++){
if (category == "name" && a[i].name == name){
return i;
}
}
return -1;
}
void sort_by_name(College a[], unsigned n){
for (unsigned i =0; i < n -1; i++){
for (unsigned j =0; j < n - i -1; j++){
if (a[j].name > a[j +1].name){
College temp = a[j];
a[j]= a[j +1];
a[j +1]= temp;
}
}
}
}
void sort_by_cost(College a[], unsigned n){
for (unsigned i =0; i < n -1; i++){
for (unsigned j =0; j < n - i -1; j++){
if (a[j].cost > a[j +1].cost){
College temp = a[j];
a[j]= a[j +1];
a[j +1]= temp;
}
}
}
}
void sort_by_acceptance(College a[], unsigned n){
for (unsigned i =0; i < n -1; i++){
for (unsigned j =0; j < n - i -1; j++){
if (a[j].acceptance_rate > a[j +1].acceptance_rate){
College temp = a[j];
a[j]= a[j +1];
a[j +1]= temp;
}
}
}
}

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 Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

Given x 237, 220, and 12.3, find z.

Answered: 1 week ago