# Homework 1: Building Histograms Solution

\$30.00

Category:

## Description

How to turn in:

• Write three programs and submit them on iLearn

• If you write the programs in repl.it, the files will be named main.cpp; you will need to rename them

• The names are in the assignment; incorrect names will be graded as 0

Before doing this homework, read the slides named read_data_from_input_file.ppton iLearn to understand how you can read integer numbers from an input data file

Part 1: Distinct Numbers (10 points)

This program should:

1. Read an input file name from a user (note: the input file contains several integer numbers)

1. Display the minimum number among the input values

1. Display a list of distinct elements in the input and the number of occurrences of each distinct value

1. Be submitted as hw1-1.cpp

For the assignment, you can assume that the number of input values in a file can’t be more than 30.

This is a sample execution of your program. For the assignment, your program has to display the result exactly as the sample run. User input is in bold.

Enter input file name: t1.txt

Min Number: -3

 Number Count 2 3 1 1 -3 1

For the sample run, this is the input file t1.txt. Note that the first number (5) in the file indicates that there are 5 values (= 2, 1, 2, -3, 2) in the file.

5

2

1

2

-3

2

This is another sample run:

Enter input file name: t2.txt

1Min Number: -5

Number Count

-5 1

1 1

• 2

• 2

1. 1

21

This is the content of the input file t2.txt:

8

-5

1

5

3

10

2

3

5

Part 2: Horizontal Histogram (5 points)

This program should:

1. Read an input file name from a user (note: the input file will always contain exactly five integers)

1. Draw a horizontal histogram for the numbers

1. Be submitted as hw1-2.cpp

For example, let’s assume that an input file named t3.txt in your repl has the following numbers.

5

2

1

3

7

A sample run of your program should look exactly as below (user input in bold):

Enter input file name: t3.txt

===== Horizontal Histogram =====

1. *****

1. * *

1. *

1. * * *

1. *******

This is another sample input file named t4.txt which includes the following numbers.

1

1

5

2

4

This is the sample run with the file.

Enter input file name: t4.txt

===== Horizontal Histogram =====

1. *

1. *

1. *****

1. * *

4:****

Part 2: Vertical Histogram (10 points)

This program should:

1. Read an input file name from a user (note: the input file will always contain exactly seven integers)

1. Draw a horizontal histogram for the numbers

1. Have a height of the vertical histogram the same as the maximum value in the data set

1. Be submitted as hw1-3.cpp

For example, let’s assume that an input file named t5.txt in your repl has the following numbers.

5

2

1

3

7

4

2

A sample run of your program should look exactly as below (user input in bold).

Enter input file name: t5.txt

===== Vertical Histogram =====

*

*

* *

* * *

* * * *

** ****

*******

————-

5213742

This is another sample input file named 6.txt which includes the following numbers.

1

1

5

2

4

5

2

This is the sample run with the file.

Enter input file name: t6.txt

 ===== Vertical Histogram ===== * * * * * * * * * **** ******* ————- 1 1 5 2 4 5 2

Reminder: Include the header comment as described below. If you miss parts, you will get the penalty.

/*

• Title: hw1_1.cpp

• Abstract: This program displays a message Hello World on the screen.

• Author: Dr. Gross

• Email: jgross@csumb.edu

• Estimate: 4 hours

• Date: 5/5/1955

*/

#include <iostream>

using namespace std;

int main(){

cout << “Hello World!\n”;

return 0;

}

4

error: Content is protected !!