Expert Answer
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: