CS201 Assignment 2 Solution and Discussion
-
Re: CS201 Assignment 2 Solution and Discussion
Assignment No. 2Semester: Spring 2020
CS201 – Introduction to Programming Total Marks: 20Due Date:
16-6-2020Instructions
Please read the following instructions carefully before submitting assignment:
It should be clear that your assignment will not get any credit if:o Assignment is submitted after due date.
o Submitted assignment does not open or file is corrupt.
o Assignment is copied (From internet/students).Software allowed to develop Assignment
- Dev C++
Objectives:
In this assignment, the students will learn:
• How to fill / populate a two-dimensional array using given source data.
• How to write user defined functions and pass an array to them as parameter.
• How to use if statement and do while loop.
• How to calculate the percentage in elements of array.
• How to display array elements.Assignment Submission Instructions
You are required to submit only .cpp file on the assignments interface of CS201 at VU-LMS. Assignment submitted in any other format will not be accepted and will be graded zero marks.Problem Statement
Write a menu in C++ which should show the country code and name at the start of application:- Press 0 for Pakistan.
- Press 1 for China.
- Press 2 for Italy.
- Press 3 for UK.
- Press 4 for Iran.
- Press 5 for France.
- Press 6 for Turkey.
- Press 7 to exit.
Instructions to write C++ program:
Write functions to calculate % of recovered patients, % of deaths in specific country . Following function names should be used for consistency.
To display all elements in matrix form showElements( ); Percentage of death PercentageDeath ( ): Percentage of recovered PercentageRecovered(); Source data:
Country Code Total Cases Total Deaths Total Recovered 0 560,433 22,115 32,634 1 156,363 19,899 34,211 2 84,279 10,612 0 3 82,160 3,341 77,663 4 71,686 4,474 43,894 5 56,956 1,198 3,446 6 5,374 93 1095 Sample Output:
First, user will call the showElements() method to display all the data in matrix form:
Then, it will display a menu to calculate the percentage of dead and recovered persons for specific country:
If user presses 0 then it will show the percentage of dead and recovered persons for Pakistan:

If user presses 1 then it will show the percentage of dead and recovered persons for China:

If the user enters option other then 0 to 7. Following messages display:
Choice should be between 0 and 7
Invalid choice, please select again:

Good Luck
Lectures Covered: This assignment covers Lecture # 11-15.
Deadline: The deadline to submit your assignment solution is 16-6-2020. Your assignment must be submitted within the due date through VU-LMS. No assignment will be accepted through email after the due date. -
code please?
-
code please?
@zaasmi said in CS201 Assignment 2 Solution and Discussion:
code please?
#include<iostream> using namespace std; // Declaration of function showElements void showElements(long s[][4]); // Declaration of function PercentageDeath void PercentageDeath(long s[][4], int i); // Declaration of function PercentageRecovered void PercentageRecovered(long s[][4], int i); main() { cout<<"\n\nCS201 Assignment No. 2 Solution \n\n"; long source_data[7][4]= {0,560433, 22115, 32634, 1,156363, 19899, 34211, 2,84279, 10612, 0, 3,82160, 3341, 77663, 4,71686, 4474, 43894, 5,56956, 1198, 3446, 6,5374, 93, 109}; showElements(source_data); int user_choice; do { cout<<"\nPress the country code to calculate percentage of dead and recovered persons\n"; cout<<"\n*** Press 0 for Pakistan ***"; cout<<"\n*** Press 1 for China ***"; cout<<"\n*** Press 2 for Italy ***"; cout<<"\n*** Press 3 for UK ***"; cout<<"\n*** Press 4 for Iran ***"; cout<<"\n*** Press5 for France ***"; cout<<"\n*** Press 6 for Turkey ***"; cout<<"\n*** Press 7 to Exit ***"; cout<<"\n\nPlease select an option use number from 0 to 7 : "; input: cin>>user_choice; if(user_choice>=0 && user_choice<=6) { PercentageDeath(source_data, user_choice); PercentageRecovered(source_data, user_choice); } else if(user_choice<0 || user_choice>7) { cout<<"\n\nChoice should be between 0 to 7 "; cout<<"\ninvalid choice ! please select again : "; goto input; } }while(user_choice!=7); } // definition of function showElements void showElements(long s[][4]) { cout<<"Source Data : \n\n"; cout<<"Country\tCases\tDeaths\tRecovered\n\n"; for(int i=0; i<7; i++) { for(int j=0; j<4; j++) { cout<<s[i][j]<<"\t"; } cout<<"\n"; } } // definition of function PercentageDeath void PercentageDeath(long s[][4], int i) { float d_rate=(float)100*s[i][2]/s[i][1]; cout<<"\nPercentage of death is "<<d_rate; } // definition of function PercentageRecovered void PercentageRecovered(long s[][4], int i) { float r_rate=(float)100*s[i][3]/s[i][1]; cout<<"\n\nPercentage of recocered is "<<r_rate<<"\n"; }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login


































