Help with C++ code. Reading file from output?

Can someone please help me get started on this code?

You are burning some music CDs for a party. You’ve arranged a list of songs in
the order in which you want to play them. However, you would like to maximize
your use of space on the CD, which holds 80 minutes of music. So, you want to
figure out the total time for a group of songs and see how well they fit.
Using functional decomposition, write program in C++ to help you do this. The
data will be read from an input file called songs.dat which you will create at
your local machine and its data is shown below.
The duration of each song read from songs.dat is recorded in seconds. Hence, if
the data read from file is 310, it means that the song’s duration is 310 seconds.
You will need to convert this to minutes and seconds, which will yield 5 minutes
and 10 seconds (See example in table below).
As you read each data from your input file, you need to keep a running total of
all the duration of all the songs read. This running total will be displayed each
time you read a new data value. Once completed reading the file, you will need to
display how much space left in the CD in terms of minutes and seconds; remember
that the total capacity is 80 minutes.
You will need to write the output both to the screen and also an output file called outsongs.dat
A sample run of the output could be like this:
Song Song Time Total Time
Number Minutes Seconds Minutes Seconds
1 5 10 5 10
2 7 42 12 52
5 4 19 17 11
3 4 33 21 44
4 9 27 31 11
6 8 55 40 6
7 5 0 45 6
There are 34 minutes and 54 seconds of space left on the 80 minute CD.

Input validation
Songs should have a minimum of 1 minute and a maximum of 10 minutes. Hence test
for any values less than 60 seconds or more than 600 seconds. You don’t need to
display any message for songs less than 1 minute or more than 10 minutes but your
code must account for it by not including them in the calculation.
Thoroughly test the program using data set shown below.
Content of the file songs.dat
310
482
601
259
983
273
567
-12
535
45
300
Last edited on
closed account (o3hC5Di1)
Hi there,

Your assignment states "using functional decomposition". The assignment seems written like a lot of the sentences actually do that for you.

you want to figure out the total time for a group of songs and see how well they fit.
evaluate_disc_space()

The data will be read from an input file called songs.dat which you will create at your local machine and its data is shown below.
read_data_from_file(file, container)

Etc. Etc.

It seems wise to create a struct representing the song, for instance:

1
2
3
4
5
6
struct song
{
    int minutes, seconds;

    void set_duration(int seconds); //"The duration of each song read from songs.dat is recorded in seconds."
};


That should help you on your way.
Please do let us know if you require any further help.

Edit: Please don't double-post. If your previous post goes down the listing, add a polite bump post to it.

All the best,
NwN
Last edited on
Topic archived. No new replies allowed.