Question & Answer: A cars dealer keeps data about its motors in a tabular format similar the table given below. The file name is…..

A cars dealer keeps data about its motors in a tabular format similar the table given below. The file name is vehicles.text. Note that the text fields in the cells of this table DO NOT contain spaces or tabs. Download the complete file from blackboard and store it in your final exam folder. You are free to use parallel arrays (of suitable data types) or a vector of a Car structure struct Cart(…..);) to answer the following questions. a) Write functions to perform the following: [DO NOT USE GLOBALVARIABLES] A function to read all the data from the given file and store them in the arrays or vector received as parameters. The function must return the value of size of the arrays (i.e., the number of records read from the file). The function should close the file immediately after all the date are read. A void function to display the contents of the arrays or vector on the computer’s console in a nice tabular format. It should receive as parameters all the parallel arrays and the size or just the vector. A void function similar to the above one, but with an additional double parameter called askedPrice. Rows to be displayed are those for which the price =4. A void function similar to that of question a4, but it displays details of the least expensive motor by the askedMaker. A double function to return the value of all the cars In the main() function, your program should do the following: Declare the vector or parallel arrays with appropriate types and a reasonable size. 1 Load the vector or the arrays with data from the given file. 2. Display all the cars your autoDealer have. 3. Display all the cars with price
Q1. Perform the following 119 marks] A cars dealer keeps data about its motors in a tabular format similar the table given below. The Aore than the terr fields in the cells of this wable Do NOT contain spaces or tahs Download the complete flue from Blackboard and store ar in veur final eaam Selder You are free to use parallel arrays (of suitable data types) or a vector of a Car structure struct Cart a to answer the following questions. Requirements a) Write functions to perform the following: DO NOT USE GLOBALVARIABLES1 [14 marks] 1. read Data0: A function to read all the data from the given file and store them in the arrays or vector received as parameters. The function must returm the value of size of the arrays Ge the number of records read from the file). The function should close the file immediately aner all the 2. displayCarso: A void function to display the contents of the arrays or vector on the computers console in a nice tabular format. It should receive as parameters all the parallel and the size or just the vector an additional double display Cars 0: A void function similar to the above one, but with parameter called askedPrice Rows to be displayed are those for which the price askedPrice displayCars 0: A void function similar to the above one, but instead of the askedPrice, it receives a string parameter called askedMaker. Rows displayed are those for which the maker 5. displayHighstocko: A void function similar to the function in question a2. but rows displayed are those for which the amount m4. 6, displayLeastExpensive0: A void function similar to that of question aa, but it displays details of the least expensive motor by the askedMaker. 7. gerTotalvalue0: A double function to return the value of all the cars Chint: the sum of price amount for all the cars) b) In the main0 function, your program should do the following: (No menu is required) lsmar Declare the vector or parallel amays with appropriate types and a reasonable size. 1. Load the vector or the arrays with data from the given file. 2. Display all the cars your autoDealer have. 3. Display all the cars with price 85000. 4. Display all the cars made by Nissan. 5. Display the least expensive car by Toyota. 6. Display the total value of the cars in the given file. 7. Display the high stock List. c) Run your program. Take a screenshot of the output window. Add a copy of your cpp file and the screenshot (s) to the MS-Word document. Save your file and project.

Expert Answer

 You should have given the link for the txt file. As a result i cant test my code properly. But still i wrote it.

Source Code:

#include <iostream>
#include<stdio.h>
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<conio.h>
using namespace std;
struct car
{
int serial,amt;
char brand[50],maker[50];
float price;
};
int readdata(struct car a[50]){
fstream fin;
int i=0;
fin.open(“vehicles.txt”,ios::in);
while(fin){
fin.read((char *)& a[i],sizeof(car));
i++;
}
fin.close();
return i;
}
void displaycars(struct car a[50],int i)
{
cout<<“nserialtmakertbrandtpricetamountn”;
for(int j=0;j<i;j++)
{
cout<<a[j].serial<<“t”;
puts(a[j].maker); cout<<“t”;
puts(a[j].brand); cout<<“t”;
cout<<a[j].price<<“t”<<a[j].amt;
}
}
void displaycars(struct car a[50],int i,double ap)
{
cout<<“nserialtmakertbrandtpricetamountn”;
for(int j=0;j<i;j++)
{
if(a[j].price<=ap){
cout<<a[j].serial<<“t”;
puts(a[j].maker); cout<<“t”;
puts(a[j].brand); cout<<“t”;
cout<<a[j].price<<“t”<<a[j].amt<<“n”;
}
}
}
void displaycars(struct car a[50],int i,char* am)
{
cout<<“nserialtmakertbrandtpricetamountn”;
for(int j=0;j<i;j++)
{
if(strcmp(a[j].maker,am)==0){
cout<<a[j].serial<<“t”;
puts(a[j].maker); cout<<“t”;
puts(a[j].brand); cout<<“t”;
cout<<a[j].price<<“t”<<a[j].amt;
}
}
}
void displayhighstock(struct car a[50],int i)
{
cout<<“nserialtmakertbrandtpricetamountn”;
for(int j=0;j<i;j++)
{
if(a[j].amt>=4){
cout<<a[j].serial<<“t”;
puts(a[j].maker); cout<<“t”;
puts(a[j].brand); cout<<“t”;
cout<<a[j].price<<“t”<<a[j].amt;
}
}
}
void displayleastexpensive(struct car a[50],int i,char* am)
{
cout<<“nserialtmakertbrandtpricetamountn”;
int j,h,temp;
for(j=0;j<i;j++)
{
if(((strcmp(am,a[j].maker))==0))
{
temp=a[j].price;
goto aman;
}
}
aman:
for(;j<i;j++)
{
if(a[j].price<temp)
{
temp=a[j].price;
h=j;
}
}
for(int j=0;j<i;j++)
{
if((strcmp(am,a[j].maker))==0 && j==h){
cout<<a[j].serial<<“t”;
puts(a[j].maker); cout<<“t”;
puts(a[j].brand); cout<<“t”;
cout<<a[j].price<<“t”<<a[j].amt;
}
}
}
double gettotalvalue(struct car a[50],int i)
{
double sum=0;
for(int j=0;j<i;j++)
{
sum=sum+a[j].price;
}
return sum;
}
void main()
{
clrscr();
car a[50];

int i;
i=readdata(a);
displaycars(a,i);
displaycars(a,i,85000);
displaycars(a,i,”nissan”);
displayleastexpensive(a,i,”toyota”);
cout<<gettotalvalue(a,i);
displayhighstock(a,i);
getch();
}

Screenshots:

Still stressed from student homework?
Get quality assistance from academic writers!