Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3761492 • Letter: A

Question

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.dat. and this file has been opened using ifstream variable inFile.)

Write a C++ program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions: Function getData: This function reads and stores data in the two-dimensional array. Function averageHigh: This function calculates and returns the average high temperature for the year. Function averageLow: This function calculates and returns the average low temperature for the year. Function indexHighTemp: This function returns the index of the highest high temperature in the array. Function indexLowTemp: This function returns the index of the lowest low temperature in the array. (These functions must all have the appropriate parameters.)

Explanation / Answer

1) import java.util.*;
import java.io.*;

public class TestScannerRead{
public static void main(String [] args){
Scanner inFile = null;
int [] cars = new int[10];

try{
inFile = new Scanner(new FileReader("cars.dat"));
for(int i = 0; i<cars.length; i++){
cars[i] = inFile.nextInt();
System.out.println("Salesperson #" + (i+1) + " sold " + cars[i] + " cars.");
}
}catch(FileNotFoundException e){
System.out.println("File Not Found");
}catch(NoSuchElementException e){
System.out.println("File is Empty");
}
}
}

2)   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote