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:
using namespace std;
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 ";
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;
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. ";
cout << " ";
Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*See Solution
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...
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...
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...
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...
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...
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...
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<string> Rectified- #include<...
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 ...
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 ...