Module/Week4 ASSIGNMENT (CONTROL STRUCTURES . WHILE, FOR, Do, CASE)You are burning some music CDs for a party. You have arranged a list of songs in the order you want to play them.However, you would like to maximize your use of space on the CD, which holds 80 minutes of music. To do so, youwant to figure out the total time for a group of songs and see how well they fit. Write a design and a C++ program tohelp you accomplish this task. The data are on file "songs.txt" (which is provided for you). The time is entered asseconds. For example, if a song takes 7 minutes and 42 seconds to play, the data entered for that song would be 462.After all the data has been read, the application should print a message indicating the time remaining on the CD. Theoutput must be in the form of a table with columns and headings written on a file. For example:Song TimeMinutes SecondsTotal TimeSecondsSongNumberMinutes15105101217274421952114411333272132106855416467506There are 33 minutes and 54 seconds of space left on the 80-minute CD.Note: the output converts the input from seconds to minutes and seconds. Use meaningful variable names, properindentation, and appropriate comments. Thoroughly test the program using your own data sets.Use meaningful variable names, proper indentation, and appropriate comments. Thoroughly test the program usingthe data set found in songs.txt file provided for you.gogstt

Question
Asked Dec 3, 2019
46 views

Module/Week 4 Assignment (Control Structures   . While, For, Do, Case)

You are burning some music CDs for a party. You have arranged a list of songs in the order you want to play them. However, you would like to maximize your use of space on the CD, which holds 80 minutes of music. To do so, you want to figure out the total time for a group of songs and see how well they fit. Write a design and a C++ program to help you accomplish this task. The data are on file “songs.txt” (which is provided for you). The time is entered as seconds. For example, if a song takes 7 minutes and 42 seconds to play, the data entered for that song would be 462.

 

After all the data has been read, the application should print a message indicating the time remaining on the CD. The output must be in the form of a table with columns and headings written on a file. For example:

 

Note: the output converts the input from seconds to minutes and seconds. Use meaningful variable names, proper indentation, and appropriate comments. Thoroughly test the program using your own data sets.

 

Use meaningful variable names, proper indentation, and appropriate comments. Thoroughly test the program using the data set found in songs.txt file provided for you.

// the data is the following it was txt extension but your system only allow jpg , png among others but somehow does not allow me to attach the txt file.  the data is the following:

310
462
627
273
300
535
259
625
736
122

 

 

Module/Week4 ASSIGNMENT (CONTROL STRUCTURES . WHILE, FOR, Do, CASE)
You are burning some music CDs for a party. You have arranged a list of songs in the order you want to play them.
However, you would like to maximize your use of space on the CD, which holds 80 minutes of music. To do so, you
want to figure out the total time for a group of songs and see how well they fit. Write a design and a C++ program to
help you accomplish this task. The data are on file "songs.txt" (which is provided for you). The time is entered as
seconds. For example, if a song takes 7 minutes and 42 seconds to play, the data entered for that song would be 462.
After all the data has been read, the application should print a message indicating the time remaining on the CD. The
output must be in the form of a table with columns and headings written on a file. For example:
Song Time
Minutes Seconds
Total Time
Seconds
Song
Number
Minutes
1
5
10
5
10
12
17
2
7
4
42
19
52
11
44
11
3
33
27
21
32
10
6
8
55
41
6
46
7
5
0
6
There are 33 minutes and 54 seconds of space left on the 80-minute CD.
Note: the output converts the input from seconds to minutes and seconds. Use meaningful variable names, proper
indentation, and appropriate comments. Thoroughly test the program using your own data sets.
Use meaningful variable names, proper indentation, and appropriate comments. Thoroughly test the program using
the data set found in songs.txt file provided for you.
gogstt
help_outline

Image Transcriptionclose

Module/Week4 ASSIGNMENT (CONTROL STRUCTURES . WHILE, FOR, Do, CASE) You are burning some music CDs for a party. You have arranged a list of songs in the order you want to play them. However, you would like to maximize your use of space on the CD, which holds 80 minutes of music. To do so, you want to figure out the total time for a group of songs and see how well they fit. Write a design and a C++ program to help you accomplish this task. The data are on file "songs.txt" (which is provided for you). The time is entered as seconds. For example, if a song takes 7 minutes and 42 seconds to play, the data entered for that song would be 462. After all the data has been read, the application should print a message indicating the time remaining on the CD. The output must be in the form of a table with columns and headings written on a file. For example: Song Time Minutes Seconds Total Time Seconds Song Number Minutes 1 5 10 5 10 12 17 2 7 4 42 19 52 11 44 11 3 33 27 21 32 10 6 8 55 41 6 46 7 5 0 6 There are 33 minutes and 54 seconds of space left on the 80-minute CD. Note: the output converts the input from seconds to minutes and seconds. Use meaningful variable names, proper indentation, and appropriate comments. Thoroughly test the program using your own data sets. Use meaningful variable names, proper indentation, and appropriate comments. Thoroughly test the program using the data set found in songs.txt file provided for you. gogstt

fullscreen
check_circle

Expert Answer

Step 1

Program:

#include <iostream>

#include <iomanip>

#include <fstream>

 

using namespace std;

 

int main()

{

double temp;

int i;

int invalidData = 0;

int sSeconds = 0, tSeconds = 0, rSeconds = 0;

int sMin=0, sSec=0, tMin=0, tSec=0, rMin=0, rSec=0;

fstream fin("songs.txt", ios::in);

fstream fout("result.txt", ios::out);

i = 1;

fout << " " << " Song " << setw(10) << " Song " << setw(15) << "Time " << setw(10) << " Total " << setw(10) << "Time ";

fout << " " << "\n Number " << setw(10) << " Minutes" << setw(15) << "Seconds " << setw(10) << " Minutes" << setw(10) << " Seconds ";

 

while(fin.good())

{

fin >> sSeconds;

if(sSeconds >= 60 && sSeconds <= 600)

{

sMin = sSeconds / 60;

sSec = sSeconds % 60;

tSeconds += sSeconds;

tMin = tSeconds / 60;

tSec = tSeconds % 60;

 

fout << "\n " << i << setw(10) << " " << sMin << setw(15) << sSec << setw(10) << tMin << setw(10) << tSec;

i++;

}

else

{

invalidData++;

}

rSeconds = 4800 - tSeconds;

rMin = rSeconds / 60;

rSec = rSeconds % 60;

}

fout << "\nThere are " << rMin << " minutes and " << rSec << " seconds of space left on the 80 minutes CD. ";

fin.close();

fout.close();

 

cout << " ";

return 0;

}

Step 2

Input file:

Filename: songs.txt

...
help_outline

Image Transcriptionclose

saved songs.txt 310 1 2 462 627 273 4 5 з00 6 535 7 259 625 736 122 10

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Python Coding-While Loops  (In PyCharm Community edition)   Create a while loop that SUMS up ALL the...

A: Prompt user to enter initial numberPrompt user to enter ending numberUsing while loop sums up all th...

question_answer

Q: using an array write a program that will ask the user to enter a temperature for each day of the wee...

A: The following program is run and developed under C++ environment.Array temperature declared with siz...

question_answer

Q: Write a method named sumInts that can take a variable number of int arguments and return the sum of ...

A: Below is the approach, and a java program to display the sum of integer arguments, passed in the sum...

question_answer

Q: Write a program that reads integers from a file, sums the values and calculates the average. Write...

A: The below given C++ program will obey the following rubrics:Importing essential header files.Definin...

question_answer

Q: Write a recursive function rec_string that produces the output shown below for the corresponding fun...

A: Program Algorithm-STARTStep1: Define the rec_string method.Step2: Compare the length of string to ze...

question_answer

Q: Find the employment age of each employee?

A: Select empno, ename datediff(YY,hiredate ,getdate()) as emp from emp; The above query prints the emp...

question_answer

Q: The following code I have written is supposed to check if the first character of the first given com...

A: Correction in the code- 1)Error in header file-    #include&lt;string&gt;   Rectified-   #include&lt...

question_answer

Q: Find the location that has average salary more than 4000 dollars. Usually each location mayhave seve...

A: SubqueryA subquery is a query within another query. A subquery is a query that is embedded in WHERE ...

question_answer

Q: Forest and domain functional level means Windows Operating System version. true or false

A: The Forest functional level is used to enable features across all the domains inside the forest. It ...