Question

Assignment • No variables declared after you start writing code, must be declared at the top....

Assignment

• No variables declared after you start writing code, must be declared at the top.

• Reuse all the variables from the first half in the second half, do not make up new variable names.

• You code must be properly formatted.

• You must use the code provided and variables names provided and not add any more variables to your code.

• No for(int I = 0; … no declaring variables except at top of code.

• You cannot use the and operator and must use nested if else statements.

• You read loop must be controlled by scanf not a counter.

• You must initialize sum, min and max to the first number in the file

You will use one file from the first half of this assignment, copy them into the proper directory for this program.

num1.txt

Open the file for reading, read each number one at a time and calculate the Sum, count, max, min, average and create bins for a histogram.

The Assignment

Read file get statistics

Print out a horizontal bar chart for each bin range

1-5, 6-10, 11-15, 16-20

Bin counter variables

There are 4 bin counter variables bc5, bc10, bc15, bc20

Bc5 count of all numbers read that are 1 thu 5, Bc10 count of 6 thu 10 and so forth

When all numbers are read each should have a count of all numbers in each bin’s range.

To Start

Initialize your bin counters and count to 0

Open the file num1.txt for reading

Read the first number and assign it to sum, min, and max

do

Count it

Add to sum

See if is new max or min

Use nested if else statements to add one to the proper bin variable

If n < 6 bc5 = bc5 + 1 and so forth

Do While scanf reads something stored in n

Close file

Print out sum, count, average, min and max

Each bin

Print range so they line up on each line

A loop to print an x for the number stored in the bc variable.

Code

#include <stdio.h>

int main(int argc, char * argv[]) {

int n, count, min, max, sum;

int bc5, bc10, bc15, bc20;

FILE * fileptr;

// your code goes here

printf("Press enter to quit: ");

getchar();

return 0; }

num1.txt File:

4 15 16
3 19 16
19
4 12 15 15
2
2 5
19 9 5 12
16
3 20 20 15
12 7
2 18
19 18
5
14 7
5 18
13 5 9 10
20 2 10 5
18 2 20 19
7 15 1
9
4 20 17
10
9
12
14 18 8 9
9 8 17
10
7
9 19 4
13 19
4 3 1 10
5 12
18 17
17 20
8 13 3
20
10
9 18
5 17
17 13

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Assignment • No variables declared after you start writing code, must be declared at the top....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Statistics Macro Assignment Write a macro to find the number of observations, max, min, sum, aver...

    Statistics Macro Assignment Write a macro to find the number of observations, max, min, sum, average and standard deviation for a column of numbers with any number of observations starting in cell A1 and proceeding downward. The number set will be of any length and include negative, zero, and positive integers. Display the results as shown below. Use the numbers below as an example. You may use the key board code “Selection.End(xlDown).Select” if you wish. Otherwise, use only VBA code...

  • C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <...

    C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <iostream> #include <fstream> #include <string> using namespace std; int measureElementsPerLine(ifstream& inFile) {    // Add your code here.    string line;    getline(inFile, line);    int sp = 0;    for (int i = 0; i < line.size(); i++)    {        if (line[i] == ' ')            sp++;    }    sp++;    return sp; } int measureLines(ifstream& inFile) {    // Add your code here.    string line;    int n = 0;    while (!inFile.eof())    {        getline(inFile,...

  • Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in...

    Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in C++ Implementing classes Using vectors Using command line arguments Modifying previously written code Tasks For this project, you will implement a simulation for predicting the future populations for a group of animals that we’ll call prey and their predators. Given the rate at which prey births exceed natural deaths, the rate of predation, the rate at which predator deaths exceeds births without a food...

  • In which line of the following code the first error is appeared (if any)? #include 2...

    In which line of the following code the first error is appeared (if any)? #include 2 int main() <stdio.h> 4 file p: 6 fopen("newname . txt", "rb"); *p if = (P NULL) 8 perror( "Error opening file") 9 else f while (fgetc(p)- eof) 12 13 if (feof(p)) 14 15 else 16 17 Fclose(p) 18 19 20 return e; 21 printf("%d\n", n); puts("End-of-File was not reached.) 23 O 10 0 17

  • Using the variables shown below and a EOF-controlled loop write a set of C++ statements that...

    Using the variables shown below and a EOF-controlled loop write a set of C++ statements that accumulate the values read from the file in total as long as total does not get greater than max. For example, if the content of the input file is: 10 25 17 6 24 23 12 5 For max = 100, the value in total should be 82 (10+25+17+6+24) For max = 75, the value in total should be 58 (10+25+17+6) Assume that max...

  • Lab 6.6 – Using Value and Reference Parameters Below is a copy of the source code....

    Lab 6.6 – Using Value and Reference Parameters Below is a copy of the source code. 1 // Lab 6 swapNums.cpp -- Using Value and Reference Parameters 2 // This program uses a function to swap the values in two variables . 3 // PUT YOUR NAME HERE. 4 #include <iostream> 5 using namespace std; 6 7 // Function prototype 8 void swapNums(int, int); 9 10 /***** main *****/ 11 int main() 12 { 13 int num1 = 5, 14...

  • I posted this question earlier but realized that the code was not easy to test since...

    I posted this question earlier but realized that the code was not easy to test since it was just screenshots and not text so I am reposting it: I'm very new at working with file streams, and I'm having trouble with a HW assignment I have to work on. For the assignment I have to read an input file named "MagicSquaresIn.txt" (included at the bottom) and I have to check whether they are normal, associative, and panmagic. To check that...

  • Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global...

    Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global variables should be used. PART B: (Statistics Program) – (50%) Please read this lab exercise thoroughly, before attempting to write the program. Write a program that reads the pairs of group number and student count from the text file (user must enter name of file) and: Displays the number of groups in the file (5 %) Displays the number of even and odd student...

  • Language: Java 30 pts. ) - This assignment revisits the student parsing program from earlier in...

    Language: Java 30 pts. ) - This assignment revisits the student parsing program from earlier in the quarter, but challenges you to restructure the component pieces of the program to create a cleaner, more succinct Main(). You will generate a Student class of object and load an Array List with student objects, then report the contents of that Array List. To do so, you must perform the following: A)(10 /30 pts.)- Generate a class file “myStudent.java” (which will generate myStudent.class...

  • Assignment 1 In this assignment you will be writing a tool to help you play the...

    Assignment 1 In this assignment you will be writing a tool to help you play the word puzzle game AlphaBear. In the game, certain letters must be used at each round or else they will turn into rocks! Therefore, we want to create a tool that you can provide with a list of letters you MUST use and a list of available letters and the program returns a list of all the words that contain required letters and only contain...

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