I need some help

I'm having a difficulty making the program below. Can someone make me one? I will appreciate it very much. Thanks.

General Specifications

1. You are allowed to use ONLY the following header files: iostream, fstream,
iomanip, and cmath.
2. User-defined functions are not allowed.
3. Use of string data type is not allowed.
4. There will be no console input. All input data must be read from a file. Output must be
displayed on screen.
5. Test your program before submitting.


Input:

First line of input contains the number of data to be evaluated. Each line contains a non-negative whole
number N, where 0 < or = N < or = 1000000.

Output:

For each line of input, return the number converted into the correct amount format. If the number N
exceeds or is below the limit, output “--.--". Since we are dealing with amounts, all must be properly
right aligned.

Sample Input:

4
1000
20100
3031
1

Sample Output

_1,000.00
20,100.00
_3,031.00
_____1.00


Second


Input:

First line of input contains the number of teams T in the competition and the number of rounds R they have competed. The succeeding lines contain the teams with their corresponding scores for the rounds. Assume that each round is worth 100 points.

Output:

You are to return the name of the teams with their corresponding scores arranged from first to fifth place. Assume that no teams will have the same general average.

Sample Input:

6 4
A 10 20 10 20
P 20 20 20 80
T 100 80 90 100
H 80 80 80 80
K 90 90 90 90
G 100 0 0 100

Sample Output:

1: T 92.5
2: K 90
3: H 80
4: G 50
5: P 35
Last edited on
For the right alignment of your output in first program you can check this: http://recurseit.blogspot.com/2011/09/right-align-your-output.html
No one is going to do your homework for you. You must show an effort and post whatever code you have. Then we can help you fix any problems. It's important that it's done this way otherwise you won't learn the basics.
This is a fairly easy program to write. The first one wants you to understand the fundamentals of fstream, loops, and iomanip manipulators.

Include your headers:
1
2
3
#include <fstream>
#include <iomanip>
#include <iostream> 


Then start at main and make a ifstream object (thats ifstream for Input File STREAM. Don't use just fstream as it is a merged iofstream object.)

Check for the file you are opening (Very important when you are using files for input), read the first value in the text document as an int so you can use it in a for loop as the termination point for reading.

Use a for loop, reading each value thereafter as a float.
Check its range, and print the appropriate output (either the number or the space holder).
Use setw() from iomanip to space them evenly.

Important to make sure you didn't hit the EOF or the ifstream object didn't hit an error while reading floats. So be sure to add a condition to the loop to stop if the ifstream's badbit flag is set (look it up).

The second program will be easier when you get the first one done.
Last edited on
Topic archived. No new replies allowed.