Consider the following declarations: const int CAR TYPES = 2; const int COLOR TY
ID: 641986 • Letter: C
Question
Consider the following declarations: const int CAR TYPES = 2; const int COLOR TYPES = 3; double sales [CAR TYPES] COLOR TYPEs]; a. Write C++ code to ask the sales per CAR TYPE per COLOR_ TYPE from the user and store them in the sales array b. Write C++ code to sum the sales by CAR_TYPES and print a report on the screen. c. Write C++ code to sum the sales by COLOR TYPES and print a report on the screen. Save your program as lab3-2-yourName.cpp. Make sure to include comments in your program to clearly show which part of your code is answering which part Save your program as lab3-2-yourName opp. Make sure to include comments in your program to clearly show which part of your code is answering which part above. You don't have to use enumerated types in your code above. You don' t have to use enumerated types in your codeExplanation / Answer
#include <iostream>
using namespace std;
const int CAR_TYPES = 2;
const int COLOR_TYPES = 3;
double sales[CAR_TYPES][COLOR_TYPES];
int main(){
// following for loop answers part a of the question
for(int i = 0; i < CAR_TYPES; ++i){
for(int j = 0; j < COLOR_TYPES; ++j){
cout << "Sales of car type " << i << " and color type " << j << ": ";
cin >> sales[i][j];
}
}
cout << endl;
int sum = 0;
// following for loop answers part b of the question
for(int i = 0; i < CAR_TYPES; ++i){
sum = 0;
for(int j = 0; j < COLOR_TYPES; ++j){
sum += sales[i][j];
}
cout << "Sales of car type " << i << " is " << sum << endl;
}
cout << endl;
// following for loop answers part c of the question
for(int i = 0; i < COLOR_TYPES; ++i){
sum = 0;
for(int j = 0; j < CAR_TYPES; ++j){
sum += sales[j][i];
}
cout << "Sales of color type " << i << " is " << sum << endl;
}
cout << endl;
return 0;
}