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
  • 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...

  • 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...

  • can someone please comment through this code to explain me specifically how the variables and arrays...

    can someone please comment through this code to explain me specifically how the variables and arrays are working? I am just learning arrays code is below assignment C++ Programming from Problem Analysis to Program Design by D. S. Malik, 8th ed. Programming Exercise 12 on page 607 Lab9_data.txt Jason, Samantha, Ravi, Sheila, and Ankit are preparing for an upcoming marathon. Each day of the week, they run a certain number of miles and write them into a notebook. At the...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

  • Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank...

    Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank you. Here are the temps given: January 47 36 February 51 37 March 57 39 April 62 43 May 69 48 June 73 52 July 81 56 August 83 57 September 81 52 October 64 46 November 52 41 December 45 35 Janual line Iranin Note: This program is similar to another recently assigned program, except that it uses struct and an array of...

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
ADVERTISEMENT