Question

In: Computer Science

You are developing an application that prints out invoice information of customers and cars from dealers....

You are developing an application that prints out invoice information of customers and cars from dealers. The invoice contains: dealer name, customer name, customer’s phone number, car maker, building year, and total price. Please follow below instructions to write a program.

Part 1 create data types

1. Create an enumerated data type that holds 7 car colors, which are: red, black, white, blue, yellow, gray, and silver;

2. Create a structure for car that holds 4 members: car maker, building year, car color, and total price;

3. Create another structure for customer that holds 2 members: customer name, and customer phone number;

4. Create a third structure for invoice that holds 3 members: dealer name, customer information and car information. The car information is a pointer.

Part 2 define functions

1. Define a function that returns price rate base on the car color. If the car’s color is red, black or white, then the rate is 1. If the color is blue or yellow, then the rate is 1.5. If the color is gray or silver, then the rate is 2;

2. Define a function that copy each member in an invoice variable (e.g., var1) and assign these members to another invoice variable (e.g., var2). Then return this copied invoice variable (var2);

3. Define a function that display invoice information, which includes:

• Dealer name

• Customer name

• Customer phone number

• Car maker

• Car building year

• Car total price

Part 3 manipulate data

A car inventory of cars contains information of three cars: 2018 white Honda, 2019 blue BMW, 2018 silver Tesla. The initial price of each car starts at the price of $30,000. The color base price is $300, and it is varied by multiplying the price rate.

1. Define three pointers that hold char array values for car maker: Honda, BMW, Tesla;

2. Define a C++ string array that holds values of model year;

3. Define a pointer of the car’s type (car pointer) and dynamic allocate an array of size 3;

4. Define a pointer (price pointer) that dynamic allocate an array of size 3. The values pointed by the price pointer and its offsets are total price for each car;

5. Base on color information and price rate, calculate total prices and store them into price pointer and its offsets: total price = initial price + (color base price * price rate);

6. According to above information, store makers, model years, car color, and total price to the car array that pointed by car pointer.

A customer named Tom Smith comes to Carfax to buy the 2019 blue BMW. His phone number I (408)123-4567.

1. Create a variable of invoice type (invoice variable) and store dealer, customer, and car information;

2. Call the display function to print out invoice information.

Later, Tom Smith goes to KBB and buy the 2018 silver Tesla.

1. Create another variable of invoice type (copied invoice variable) and copy contents from invoice variable;

2. Modify contents in copied invoice variable to match the second transaction information;

3. Call the display function to print out this invoice information.

Solutions

Expert Solution

Screenshot

Program

#include <iostream>
#include<string>
using namespace std;
//Part1
//Create an enumerated data type that holds 7 car colors,
//which are: red, black, white, blue, yellow, gray, and silver;
enum Colors {
   red, black, white, blue, yellow, gray, silver
};
//Create a structure for car that holds 4 members: car maker, building year, car color, and total price;
struct Car {
   string maker;
   string year;
   Colors color;
   float price;
};
//Create another structure for customer that holds 2 members: customer name, and customer phone number;
struct Customer {
   string name;
   string phoneNum;
};
//Create a third structure for invoice that holds 3 members:
//dealer name, customer information and car information.
//The car information is a pointer.
struct Invoice {
   string dealerName;
   Customer customer;
   Car* car;
};
//Part2
//Function prototypes
float priceRate(Colors color);
Invoice copy(Invoice invoice);
void displayInvoice(Invoice invoice);
int main()
{
   //Part3
   //Define three pointers that hold char array values for car maker
   char maker1[] = "Honda",maker2[] = "BMW", maker3[] = "Tesla";
   char* m1;
   char*m2;
   char*m3;
   m1 = maker1;
   m2 = maker2;
   m3 = maker3;
   //Define a C++ string array that holds values of model year;
   string modelsYear[] = { "2018","2019","2018" };
   // Define a pointer of the car’s type (car pointer) and dynamic allocate an array of size 3;
   Car* cars;
   cars = new Car[3];
   cars[0].color = white;
   cars[1].color = blue;
   cars[2].color = silver;
   //Define a pointer(price pointer) that dynamic allocate an array of size 3.
   //The values pointed by the price pointer and its offsets are total price for each car;
   float* price;
   price = new float[3]{ 30000,30000,30000 };
   //Add into car array
   for (int i = 0; i < 3; i++) {
       if (i == 0) {
           cars[i].maker = m1;
          
       }
       else if (i == 1) {
           cars[i].maker = m2;
       }
       else {
           cars[i].maker = m3;
       }
       cars[i].year = modelsYear[i];
       cars[i].price = price[i] +( 300 * priceRate(cars[i].color));
   }
   // Create a variable of invoice type (invoice variable) and store dealer,
   //customer, and car information;
   Invoice invoice;
   invoice.dealerName ="Carfax";
   Customer customer = { "Tom Smith", "(408)123-4567" };
   invoice.customer = customer;
   invoice.car = &cars[1];
   cout << "Display invoice before copy:-" << endl;
   //Display invoice
   displayInvoice(invoice);
   //Create second invoice
   Invoice invoice2;
   invoice2.dealerName = "KBB";
   customer = { "Tom Smith", "(408)123-4567" };
   invoice2.customer = customer;
   invoice2.car = &cars[2];
   //Copy
   invoice=copy(invoice2);
   //Display
   cout << "\nDisplay invoice after copy:-" << endl;
   displayInvoice(invoice);

}

//Define a function that returns price rate base on the car color.
//If the car’s color is red, black or white, then the rate is 1.
//If the color is blue or yellow, then the rate is 1.5.
//If the color is gray or silver, then the rate is 2;
float priceRate(Colors color) {
   if (color == red || color == black || color == white) { return 1; }
   else if (color == blue || color == yellow) { return 1.5; }
   else{ return 2; }
}
//Define a function that copy each member in an invoice variable (e.g., var1)
//and assign these members to another invoice variable (e.g., var2).
//Then return this copied invoice variable (var2);
Invoice copy(Invoice invoice) {
   Invoice newInvoice;
   newInvoice.customer = invoice.customer;
   newInvoice.dealerName = invoice.dealerName;
   newInvoice.car = invoice.car;
   return newInvoice;
}
// Define a function that display invoice information
void displayInvoice(Invoice invoice) {
   cout << "Dealer name: " << invoice.dealerName << endl;
   cout << "Customer name: " << invoice.customer.name << endl;
   cout << "Customer phone number: " << invoice.customer.phoneNum << endl;
   cout << "Car make: " << invoice.car->maker << endl;;
   cout << "Car building year: " << invoice.car->year << endl;
   cout << "Car total price: " << invoice.car->price << endl;
}


---------------------------------------------------------------------------------------

Output

Display invoice before copy:-
Dealer name: Carfax
Customer name: Tom Smith
Customer phone number: (408)123-4567
Car make: BMW
Car building year: 2019
Car total price: 30450

Display invoice after copy:-
Dealer name: KBB
Customer name: Tom Smith
Customer phone number: (408)123-4567
Car make: Tesla
Car building year: 2018
Car total price: 30600


Related Solutions

in java Write an application that gets two numbers from the user and prints the sum,...
in java Write an application that gets two numbers from the user and prints the sum, product, difference and quotient of the two numbers in a GUI.
what special information would you want from a foreign seller, on your commercial invoice, that he...
what special information would you want from a foreign seller, on your commercial invoice, that he might not provide to one of his domestic customers?
Write code that takes the size of their foot from user and prints out suggested sandal...
Write code that takes the size of their foot from user and prints out suggested sandal size. Shoe Range Sandal Size <= 5 (inclusive) Small 5 ~ 9 (inclusive) Medium 9 ~ 12 (inclusive) Large above 12 X-Large example: Please enter your shoe size: (user types 6.5) Your sandal size is Medium.
When completing a life insurance application, if you unintentionally leave out information about plastic surgery to...
When completing a life insurance application, if you unintentionally leave out information about plastic surgery to your face five years earlier, then die a couple of years later from an auto accident, the insurance company: must pay, because once an application has been accepted, an insurer may not use a misrepresentation on the application to avoid liability. must pay, because the misrepresentation was not material and did not increase the company's risk in insuring your life. does not have to...
Description: You are to develop a Java program that prints out the multiplication or addition table...
Description: You are to develop a Java program that prints out the multiplication or addition table given the users start and end range and type of table. This time several classes will be used. You are free to add more methods as you see fit – but all the methods listed below must be used in your solution. For the class Table the following methods are required: - Protected Constructor – stores the start and size of table, creates the...
1. Write an application that prints the following diamond shape. You may use output statements that...
1. Write an application that prints the following diamond shape. You may use output statements that print a single asterisk (*), a single space or a single newline character. Maximize your use of repetition (with nested for statements), and minimize the number of output statements 2. Modify the application you wrote in Exercise 5.20 (Question 1 Above) to read an odd number in the range 1 to 19 to specify the number of rows in the diamond. Your program should...
When an invoice is received from a vendor, which file stores the detailed transaction information a....
When an invoice is received from a vendor, which file stores the detailed transaction information a. Receiving transaction file b. Open accounts payable c. Vendor master file d. Shipping transaction file
This phyton program requires you to prints out the total of a series of positive floating-pointnumbers...
This phyton program requires you to prints out the total of a series of positive floating-pointnumbers entered by the user. The user should be prompted with the message "Enter a floating-point number >= 0:". You do not need to check that the input is a FP number. If the user correctly enters a positive FP number, handle it and prompt the user for the next number with the same message. If the user enters a negative number, your program should...
/* Problem 1 * Write and run a java program that prints out two things you...
/* Problem 1 * Write and run a java program that prints out two things you have learned * so far in this class, and three things you hope to learn, all in different lines. */ You could write any two basic things in Java. /* Problem 2 * The formula for finding the area of a triangle is 1/2 (Base * height). * The formula for finding the perimeter of a rectangle is 2(length * width). * Write a...
5.24 (Diamond Printing Program) Write an application that prints the following diamond shape. You may use...
5.24 (Diamond Printing Program) Write an application that prints the following diamond shape. You may use output statements that print a single asterisk (*), a single space or a single new- line character. Maximize your use of repetition (with nested for statements), and minimize the number of output statements." Example for 2.24:    * *** ***** ******* ********* ******* ***** *** *
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT