Project Instructions Modify your code from Project 2 to make it modular. Instead of having one long main function that c

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Project Instructions Modify your code from Project 2 to make it modular. Instead of having one long main function that c

Post by answerhappygod »

Project Instructions Modify Your Code From Project 2 To Make It Modular Instead Of Having One Long Main Function That C 1
Project Instructions Modify Your Code From Project 2 To Make It Modular Instead Of Having One Long Main Function That C 1 (121.86 KiB) Viewed 27 times
Solve Using C++ and use the code from Project 2. I have pastedthe code from Project 2 down below...
#include<iostream>#include<string>#include<iomanip>using namespace std;double TIDAL = 0.01250, amazon = 0.00402, apple_music = 0.00735, spotify = 0.00437, y0utube = 0.00069;void uploadSingleSong();void uploadMultipleSongs();int main(){ srand(time(NULL)); int choice,streams; double earnings; do{ // display main menu cout << "Choose from of thefollowing menu options:" << endl << endl; cout << "\t1: Upload a singlesong to a streaming service" << endl; cout << "\t2: Upload multiplesongs to a streaming service" << endl; cout << "\t3: Exit the program"<< endl << endl; // get the choice cout << "Enter your choice <1,2 or 3>: "; cin >> choice; cin.ignore(); cout << endl; switch(choice){ case 1:{ uploadSingleSong(); break; } case 2:{ uploadMultipleSongs(); break; } case 3:{ cout<< "Thank you for using the program!" << endl; break; } default: cout<< "ERROR - NOT A VALID MENU CHOICE. " << "PLEASE TRY AGAIN." << endl <<endl; break; } }while(choice != 3); return 0;}void uploadSingleSong(){ int choice; // display the menu do{ cout << "Which Streaming Servicewill you use to upload your song?" << endl <<endl; cout << "\t1: TIDAL" <<endl; cout << "\t2: Amazon" <<endl; cout << "\t3: Apple music"<< endl; cout << "\t4: Spotify" <<endl; cout << "\t5: y0utube" <<endl; cout << endl; cout << "Enter your choice<1-5>: "; cin >> choice; cin.ignore(); cout << endl; // Validate choice if(choice < 1 || choice >5){ cout << "ERROR -NOT A VALID MENU CHOICE. " << "PLEASE TRY AGAIN." << endl <<endl; } }while(choice < 1 || choice > 5); // get artist Name char artist_name[50]; cout << "What is the artist's name? "; cin.getline(artist_name,50); cout << endl; // get song name string song_name; cout << "What is the name of the song? "; getline(cin, song_name); cout << endl; // decide the streaming service and correspondingpay_rate string streaming_service; double pay_rate; if(choice == 1){ pay_rate = TIDAL; streaming_service = "TIDAL"; } else if(choice == 2){ pay_rate = amazon; streaming_service = "Amazon"; } else if(choice == 3){ pay_rate = apple_music; streaming_service = "AppleMusic"; } else if(choice == 4){ pay_rate = spotify; streaming_service = "Spotify"; } else if(choice == 5){ pay_rate = youtube; streaming_service = "y0utube"; } // get number of streams int streams; do{ cout << "How many streams doesThe Soul have on " << streaming_service << "? "; cin >> streams; cin.ignore(); cout << endl; if (streams <= 0){ cout << "ERROR -NUMBER OF STREAMS CANNOT BE NEGATIVE." << endl; cout << endl; } } while(streams <= 0); // calculate earnings double earnings = streams * pay_rate; // display the results cout << setprecision(2) << fixed; cout << "Song Name: " << "\t\t" <<song_name << endl; cout << "Artist Name: " << "\t\t"<< artist_name << endl; cout << "Streaming Service: " << "\t"<< streaming_service << endl; cout << "Streams: " << "\t\t" <<streams << endl; cout << "Earnings: " << "\t\t" <<"$" << earnings << endl; cout << endl;}void uploadMultipleSongs(){ int choice; // display the menu do{ cout << "Which Streaming Servicewill you use to upload your song?" << endl <<endl; cout << "\t1: TIDAL" <<endl; cout << "\t2: Amazon" <<endl; cout << "\t3: Apple music"<< endl; cout << "\t4: Spotify" <<endl; cout << "\t5: y0utube" <<endl; cout << endl; cout << "Enter your choice<1-5>: "; cin >> choice; cin.ignore(); cout << endl; // Validate choice if(choice < 1 || choice >5){ cout << "ERROR -NOT A VALID MENU CHOICE. " << "PLEASE TRY AGAIN." << endl <<endl; } }while(choice < 1 || choice > 5); // decide the streaming service and correspondingcharge string streaming_service; double pay_rate; if(choice == 1){ pay_rate = TIDAL; streaming_service = "TIDAL"; } else if(choice == 2){ pay_rate = amazon; streaming_service = "Amazon"; } else if(choice == 3){ pay_rate = apple_music; streaming_service = "AppleMusic"; } else if(choice == 4){ pay_rate = spotify; streaming_service = "Spotify"; } else if(choice == 5){ pay_rate = y0utube; streaming_service = "y0utube"; } // get num songs int num_songs; do{ cout << "How many songs will beuploaded on " << streaming_service << "? "; cin >> num_songs; cin.ignore(); cout << endl; if(num_songs < 1){ cout << "ERROR -NUMBER OF SONGS CANNOT BE LESS THAN 1." << endl <<endl; } }while(num_songs < 1); // select distribution int distribution; do{ cout << "Which type ofdistribution will you use to distribute your song(s)?" <<endl; cout << "\t" << "1: MAJORLABEL" << endl; cout << "\t" << "2:INDEPENDENT LABEL" << endl; cout << endl; cout << "Enter your choice <1or 2>: "; cin >> distribution; cin.ignore(); cout << endl; if(distribution != 1 &&distribution != 2){ cout << "ERROR -INVALID DISTRIBUTION CHOSEN. Please choose from one of the optionslisted." << endl << endl; } }while(distribution != 1 && distribution !=2); // decide the lower and upper limit fordistribution long lower, upper; double label_charge_percent; if(distribution == 1){ lower = 100000; upper = 50000000; label_charge_percent = 60; } else{ lower = 10000; upper = 1000000; label_charge_percent = 30; } // to calculate running totals long total_streams = 0; // use a for loop to generate random streams forsongs for(int count = 1; count <= num_songs;count++){ // generate random streams long streams = rand()%(upper - lower +1) + lower; // add to total_streams total_streams += streams; cout << "\tSong #" << count<< "\t\t" << streams << " streams " <<endl; } cout << endl; // calculate Earnings long total_earnings = total_streams * pay_rate; double label_earnings = total_earnings *label_charge_percent / 100; double artist_earnings = total_earnings -label_earnings; // display the results cout << setprecision(2) << fixed; cout << "Streaming Service: " << "\t"<< streaming_service << endl; cout << "Streams: " << "\t\t" <<total_streams << endl; cout << "Earnings: " << "\t\t" <<"$" << total_earnings << endl; cout << "Artist Earnings: " << "\t"<< "$" << artist_earnings << endl; cout << "Label Earnings: " << "\t"<< "$" << label_earnings << endl; cout << endl;}
Project Instructions Modify your code from Project 2 to make it modular. Instead of having one long main function that contains all the statements necessary to solve the problem given in previous projects, you must write several small functions that each solve a specific part of the problem. These small functions should then be executed in the correct order to implement a complete solution. The named constants you used in previous projects should now be made global so you won't have to pass those values to any function. In addition to the main function, your code must include the specified functions. These functions must be written exactly as specified to avoid a major error penalty. Make sure your program uses the values returned from your functions. Any functions that need input to perform a task will have to accept arguments. Global variables are prohibited. Steps: 1. Use the Divide and Conquer approach described in Section 6.1 of your textbook to modularize your program. 2. Make all of your named constants global. 3. Write the following functions: Function 1- mainMenu A void function that just displays the first menu when called. See Sample Run for format. Function 2 - streaming SerivceMenu A void function that just displays the streaming services when called. Function 3-distribution LabelMenu A void function that displays the distribution label types when called. Function 4-generateStreams A function that accepts the distribution label type and returns the number of streams generated based on the guidelines in Project 2.
Function 5- calculate Earnings A function that accepts the streaming service type and the number of streams and returns the amount of money earned from the song. Function 6- calculateLabelEarnings A function that accepts the distribution label type and the amount earned from the total songs streamed and then returns the amount the distribution label earned. NOTE: All functions must be coded as instructed above. Modifying the functions (meaning adding or removing parameters, changing the return type of the function, etc...) will count as a major error (i.e., one major error deduction for each function that is modified.) 4. Save your .cpp file using the required naming format as lastName Project3.cpp (where lastName is your last name i.e. jones Project3.cpp). 5. Click the assignment link to upload your file.
Sample Run (user input enclosed in blocks) Choose from of the following menu options: 1: Upload a single song to a streaming service 2: Upload a multiple songs to a streaming service 3: Exit the program Enter your choice (1, 2, or 3): 99 ERROR NOT A VALID MENU CHOICE. PLEASE TRY AGAIN. Choose from of the following menu options: 1: Upload a single song to a streaming service 2: Upload a multiple songs to a streaming service 3: Exit the program Enter your choice (1, 2, or 3): 1 Which Streaning Service will you use to upload your song? 1: TIDAL 2: Amazon 3: Apple Music 4: Spotify 5: YouTube Enter your choice (1-5): 99 ERROR NOT A VALID STREAMING SERVICE. Please choose from the services listed. Which Streaning Service will you use to upload your song? 1: TIDAL 2: Amazon 3: Apple Music 4: Spotify 5: YouTube Enter your choice (1-5): 3 What is the artist's name? Reason What is the name of the song? The Soul How many streams does The Soul have on Apple Music? -88 ERROR NUMBER OF STREAMS CANNOT BE NEGATIVE. How many streams does The Soul have on Apple Music? 275415 Song Name: Artist Name: Streaming Service: Streams: Earnings: The Soul Reason Apple Music 225415 $2024.30 Choose from of the following menu options: 1: Upload a single song to a streaming service 2: Upload a multiple songs to a streaming service 3: Exit the program Enter your choice (1, 2, or 3>: 2
Which Streaming Service will you use to upload your song<s>? 1: TIDAL 2: Amazon 3: Apple Music 4: Spotify 5: YouTube Enter your choice (1-5): 10 ERROR NOT A VALID STREAMING SERVICE. Please choose from the services listed. Which Streaming Service will you use to upload your song<s>? 1: TIDAL 2: Amazon 3: Apple Music 4: Spotify 5: YouTube Enter your choice (1-5): 1 How many songs will be uploaded on TIDAL? -10 ERROR NUMBER OF SONGS CANNOT BE NEGATIVE. How many songs will be uploaded on TIDAL? Which type of distribution will you use to distribute your song(s)? 1: MAJOR LABEL 2: INDEPENDENT LABEL Enter your choice (1 or 2): ERROR INVALID DISTRIBUTION CHOSEN. Please choose from one of the options liste d. Which type of distribution will you use to distribute your song(s)? 1: MAJOR LABEL 2: INDEPENDENT LABEL Enter your choice (1 or 2): Song #1: Song #2: Song #3: Song #4: Song #5: Song #6: Song #7: Song #8: Streaming Service: Streans: Earnings: 128524 streams 108105 streams 113047 streams 117512 streams 118357 streams 102527 streams 118018 streams 104681 streams TIDAL 910771 $1308.51 $523.41 $785.11 Artist Earnings: Label Earnings: Choose from of the following menu options:
1: Upload a single song to a streaming service 2: Upload a multiple songs to a streaming service 3: Exit the program Enter your choice (1, 2, or 3): 3 Thank you for using the program!
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply