Question

A car dealer has 10 salespersons. Each salesperson keeps track of the number of cars sold...

A car dealer has 10 salespersons. Each salesperson keeps track of the number of cars sold each month and reports it to the management at the end of the month. The management keeps the data in a file and assigns a number, 1 to 10 to each salesperson. The following statement declares an array, cars, of 10 components of type int to store the number of cars sold by each salesperson. Int cars[10]; Write the C++ code to store the number of cars sold by each salesperson in the array cars, output the total number of cars sold at the end of each month, and output the salesperson number selling the maximum number of cars. (Assume the data is in the file cars.txt. and this file has been opened using ifstream variableinFile.) I need the coding and how to link the txt file into codeblocks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: We have to Store the input file in the place where our c++ files are stored.Then only we can access the input file .

Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// carSales.txt (Input file):

23
45
54
42
12
56
67
76
88
10

__________________

#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;


int main() {

//Creating an Array which holds car sales
int cars[10];
int sales,i=0,sum=0;
//defines an input stream for the data file
ifstream dataIn;

//Opening the input file
dataIn.open("carSales.txt");
//checking whether the file name is valid or not
if(dataIn.fail())
{
   cout<<"** File Not Found **";
return 1;
}
else
{
//Reading the data from the file
while(dataIn>>sales)
{
cars[i]=sales;
i++;
}

//Closing the intput file
dataIn.close();
}

//calculating the sum of sales
for(int j=0;j<i;j++)
{

sum+=cars[j];
}
cout<<"Total No of Cars Sold :"<<sum<<endl;
int max,maxIndx=0;
max=cars[0];
for(int j=0;j<i;j++)
{

if(max<cars[j])
{
max=cars[j];
maxIndx=j;
}

}

cout<<"Maximum car sales sold by :"<<"Person#"<<(maxIndx+1)<<endl;


return 0;
}
___________________

Output:


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
A car dealer has 10 salespersons. Each salesperson keeps track of the number of cars sold...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Create a program for a car dealer to use where you have a class for...

    Java Create a program for a car dealer to use where you have a class for Salesman, Cars, and the Records of sale. 4 salesman and 4 cars to start with but have array size for 50 cars, have space for 100 records in array. The program should have 6 options in the menu. buy car, sell car, show inventory, show salesman, show sales records, and exit. Salesman class - Name, ID number, Commision rate, Total commisions earned, Totals number...

  • 1. Chris Smith keeps track quarterly data of sport car sold by local car dealer during...

    1. Chris Smith keeps track quarterly data of sport car sold by local car dealer during last 3 years. Download the file from DataxlsxQ3 and answer the following questions: A. Create Holt’s method to minimize the MSE for the data set B. Create Holt-Winter’s additive method to minimize the MSE for the data set C. Create Holt-Winter’s multiplicative method to minimize the MSE for the data set D. Use regression analysis to fit an additive seasonal model with linear trend...

  • A salesperson also receives a bonus at the end of each month, based on the following...

    A salesperson also receives a bonus at the end of each month, based on the following criteria: If the salesperson has been with the store for five years or less, the bonus is $10 for each year that he or she has worked there If the salesperson has been with the store for more than five years, the bonus is $20 for each year that he or she has worked there. The salesperson can earn an additional bonus as follows:...

  • the source code I have is what i'm supposed to fix for the assignment at the...

    the source code I have is what i'm supposed to fix for the assignment at the bottom. cars.cpp source code: /* Program Cars.cpp reads records from file and writes them back to another file with the price member increased by 10%. */ #include <fstream> #include <iostream> #include <string> #include "car.h" // car.h header file is included here using namespace std; /* Reads data from a file and using it to populate a Car struct and then return that Car struct...

  • 1) a) The following distribution shows the number of cars sold each month by a garage...

    1) a) The following distribution shows the number of cars sold each month by a garage over a period of 3 years: 8 9 10 11 12 13 14 15 Number of cars (x) Number of months (f) 1 4 5 8 5 4 5 4 State whether the variable measured is continuous or discrete and find the mode, the mean and the median. (6 marks) b) The weight (in kg) of 40 patients of the Berkshire Hospital are summarised...

  • Honest Al's Used Cars wants to predict how many cars are sold each month. He has...

    Honest Al's Used Cars wants to predict how many cars are sold each month. He has collected data for 12 months. He needs your help in analyzing this data using moving averages. A B C 1 Number of 4-Month 2 Time Period Cars Sold Moving Avg. 3 1 70 4 2 80 5 3 66 6 4 74 7 5 64 8 6 76 71.00 9 7 72 70.00 10 8 82 71.50 11 9 82 73.50 12 10 76...

  • The Weather Service Bureau department has data representing monthly rainfall for a year and we would...

    The Weather Service Bureau department has data representing monthly rainfall for a year and we would like to create a table categorizing each month as rainy (rainfall 20% higher than average) dry (rainfall 25% lower than average) or average. The data file for monthly rain fall is called rainfall.txt. rainfall.txt 95 100 120 130 135 145 155 185 190 160 130 120 Store the data file in the same folder (lab 6) of your lab6.cpp. OutputThe year's average monthly rainfall...

  • Please help the out keeps printing twice #include #include #include #include #include using namespace std; /**...

    Please help the out keeps printing twice #include #include #include #include #include using namespace std; /** * Function to calculate the future value and return the same */ double calculateFutureValue(double presentValue, double interestRate, int months) {    double futureValue = (double)presentValue * pow((1 + interestRate), months);    return futureValue; } /** * Function to read the input file and assign the value to the variables */ unsigned int readfile(ifstream &inF, double &presentValue, double &interestRate, int &months) {    inF >>...

  • car ded analysis etermind The accompanying table shows the number of cars sold last month by...

    car ded analysis etermind The accompanying table shows the number of cars sold last month by seven employees at a car dealership and their number of years of sales experience Management would like to use simple regression analysis to estimate monthly car sales using the number of years of sales experience. Which one of the following statements describes the results of the hypothesis test that population correlation coefficient is greater than zero, using 0.05? Click the icon to view the...

  • Program in C Student Data using Structs In this assignment you will create a program (using...

    Program in C Student Data using Structs In this assignment you will create a program (using multiple .c files) to solve the following problem: You have been hired by the university to create a program that will read in input from a .txt file. This input will contain a student name, student id #, their age and their current gpa. You should use the following struct for your student data: struct Student{                 char name[50];                 int id;                 float...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT