Question

In: Computer Science

You have been hired by a used-car dealership to modify the price of cars that are...

You have been hired by a used-car dealership to modify the price of cars that are up for sale. You will get the information about a car, and then change its price tag depending on a number of factors. Write a program (a script named: 'used_cars.m' and a function named 'car_adjust.m').The script passes the file name 'cars.dat' to the function. The following information is stored inside the file:

Ford, 2010 with 40,000 miles and no accident at marked price of $6500

Lexus, 2011 with 100,000 miles and 1 accident at marked price of $40,000

Toyota, 2008 with 20,000 miles and 2 accidents at marked price of $14,000

Audi, 2012 with 10,000 miles and no accident at marked price of $45,000

The function will open the file and store its content and creates a structure with the following fields:

Make: A string that represents the make of the car (e.g. ‘Toyota’)

Year: A number that corresponds to the year of the car (e.g. 2000)

Cost: A number that holds the cost of the car (e.g. 8000)

Price: A number that holds the marked price of the car Miles:

The number of miles clocked (e.g. 85000) Accidents:

The number of accidents the car has been in. (e.g. 1)

Your function will then return the structure to the script with all the above fields, with exactly the same names. Here is how you must calculate the Cost of each car: 1. Add 4000 to the cost if the car has clocked less than 30000 miles. 2. Subtract 2000 if it has clocked more than 90000 miles. 3. Reduce the price by 1000 for every accident. From inside your script, call different elements of the structure and make sure it returns the correct values.

Solutions

Expert Solution

%Please use Matlab R2013a or later

s = car_adjust('inp.txt');

x = size(s);
for i = 1:x(2)

c = s(i).price;
if (s(i).miles < 30000)
c = c + 4000;
end
  
if (s(i).miles > 90000)
c = c - 2000;
end
  
r = s(i).accident*1000;
c = c -r;
s(i).cost = c;
fprintf('Cost of car %d = $%.2f\n',i,c);
end

function [s] = car_adjust(file)

f = fopen(file,'r');
s = [];
while ~feof(f)
line = fgets(f);
s1 = strsplit(line,', ');
make = s1(1);
s2 = strsplit(line);
year = s2(2);
c1=strsplit(line,'$');
miles = s2(4);
acc = s2(7);

if (strcmp(acc,'no'))
accident = 0;
else
accident = str2double(acc);
end
  
str = struct('make',make,'year',str2double(year),'price',str2double(c1(2)),'accident',accident,'miles',str2double(miles),'cost',0);
  
s = [s str];   
  
end

end


Related Solutions

Problem 1. Tanner owns a car dealership and sells used cars. Tanner buys a used car...
Problem 1. Tanner owns a car dealership and sells used cars. Tanner buys a used car at price $p and has no other costs. (a) What is Tanner’s total cost if he sells 10 cars? (b) What is Tanner’s total cost if he sells 20 cars? (c) What is Tanner’s total cost if he sells y cars, TC(y)? (d) What is Tanner’s average cost function, AC(y)? (e) For every additional car Tanner sells, by how much do his costs increase?...
You have been asked by the owner of a pre-owned car dealership to set up a...
You have been asked by the owner of a pre-owned car dealership to set up a way to track the cars in his inventory. He often needs to search his records for specific makes and models or cars made in certain years. He also wants to be able to generate reports based on his sales and reports on which sales representatives are doing the most business 1.Create a new a table named SALES_REP. Be sure to create attributes, set a...
Suppose that you own a car dealership and purchase (randomly select) 10 cars of a certain...
Suppose that you own a car dealership and purchase (randomly select) 10 cars of a certain make from a production run of 200 cars. Of the 200 cars, 160 are destined to last at least five years without needing a major repair. Using the hypergeometric distribution what is the probability that at least 6 of your 10 cars will last at least five years without needing a major repair.
You randomly select 36 cars of the same model that were sold at a car dealership...
You randomly select 36 cars of the same model that were sold at a car dealership and determine the number of days each car sat on the dealership’s lot before it was sold. The sample mean is 9.75 days, with a sample standard deviation of 2.39 days. Construct a 99% confidence interval for the population mean number of days the car model sits on the dealership’s lot
You randomly select 20 cars of the same model that were sold at a car dealership...
You randomly select 20 cars of the same model that were sold at a car dealership and determine the number of days each car sat on the dealership’s lot before it was sold. The sample mean is 9.75 days, with the sample standard deviation of 2.39 days. Construct a 99% confidence interval for the population mean number of days the car model sits on the dealership’s lot. Assume the days on the lot is normally distributed.
The mean price for used cars is $10,495. A manager of a Kansas City used car...
The mean price for used cars is $10,495. A manager of a Kansas City used car dealership reviewed a sample of 50 recent used car sales at the dealership in an attempt to determine whether the population mean price for used cars at this particular dealership differed from the national mean. The prices for the sample of 50 cars are shown in the table below. 9,116 11,325 10,282 8,499 11,120 7,540 9,761 12,920 7,095 12,666 13,087 7,889 7,241 10,141 11,336...
The mean price for used cars is $10,388. A manager of a Kansas City used car...
The mean price for used cars is $10,388. A manager of a Kansas City used car dealership reviewed a sample of 50 recent used car sales at the dealership in an attempt to determine whether the population mean price for used cars at this particular dealership differed from the national mean. The prices for the sample of 50 cars are contained in the Excel Online file below. Construct a spreadsheet to answer the following questions. a. Formulate the hypotheses that...
One of the cars sold by Walt's car dealership is a very popular subcompact car called...
One of the cars sold by Walt's car dealership is a very popular subcompact car called the Rhino. The final sale price of the basic model of this car varies from customer to customer depending on the negotiating skills and persistence of the customer. Assume that these sale prices of this car are normally distributed with a mean of $19900 and a standard deviation of $360. Round your answers to 2 decimal places. a. Dolores paid $19525 for her Rhino....
3 The ten most recent cars sold at a dealership have an average price of $24,525...
3 The ten most recent cars sold at a dealership have an average price of $24,525 with a standard deviation of s = $450. Assuming that the prices of all cars sold by the dealership have an approximately normal distribution, find the 98% confidence interval for the mean price of all cars sold by the dealership, to the nearest dollar. Conclusion: We can be ___________confident that the mean price of all cars sold by the dealership is between $ ________________...
Write a Java program for a car dealership. The dealer has 10 cars in the showroom...
Write a Java program for a car dealership. The dealer has 10 cars in the showroom and space for 50 cars. Each car has a unique plate number, model, color, company, and a year of manufacture. Your program should have two classes: the "Car" class has the car information and the "info" method that displays the car information. The other class is an array class "CarArray" that has four methods:" display", "insert", "find", and the "delete" method. When the program...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT