-
Re: CS201 Assignment 2 Solution and Discussion
CS201 Introduction to Programming Assignment No 02 Fall 2020 Solution / Discussion Due Date: 18-12-2020
Assignment No. 2
Semester: Fall 2020
CS201 – Introduction to Programming
Total Marks: 20
Due Date: 18-12-2020
Instructions
Please read the following instructions carefully before submitting the 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.As all of you know that presidential election was conducted in USA recently, and the entire world had an eye on the results. There were three main candidates; Donald Trump from Republicans party, Joe Biden from Democrats and Jo Jorgensen as an independent candidate. Though the strong candidates for this presidential election 2020 were Trump and Biden, and there was tough competition among them. Similarly, some states of USA have played the role of Crucial states (Winning states) to win the election. In this assignment you will be provided with data from USA election 2020 and you have to write C++ program according to the given data.
Problem Statement
Write a menu in C++ which should show the state code and name of winning states at the start of application:
Press 1 for Florida.
Press 2 for Georgia.
Press 3 for Michigan.
Press 4 to exit.
Source data:
(Use two dimensional array to store following data)
State Code
Joe Biden Votes
Donald Trump Votes
Jo Jorgensen Votes
Total Votes
1
5,284,453
5,658,847
70,046
11,013,346
2
2,465,781
2,455,428
61,894
4,983,103
3
2,790,648
2,644,525
60,287
5,495,460
[above dummy data is for assignment purpose only]
Instructions to write C++ program:Ø Write functions to calculate %age of Joe Biden votes, %age of Donald Trump votes and %age of Jo Jorgensen votes in specific State. Following function names should be used for consistency.
To display all data in matrix form
showElements( );
Percentage of Joe Biden votes
PercentageBiden (
Percentage of Donald Trump votes
PercentageTrump();
Percentage of Jo Jorgensen
PercentageJorgensen();Sample Output:
First, user will call the showElements() method to display all the source data in matrix form. Then, it will display a menu to calculate the percentage of Biden, Trump and Jorgensen votes for specific state:If user presses 1 then it will show the percentage of Biden, Trump and Jorgensen votes from state Florida.
If user presses 2 then it will show the percentage of Biden, Trump and Jorgensen votes from state Georgia.
Similarly, If user presses 3 then it will show the percentage of Biden, Trump and Jorgensen votes from state Michigan.
If the user enters option other then 1 to 4. Following messages display:
Choice should be between 1 and 4
Invalid choice, please select again:Wish you Good Luck!
Lectures Covered: This assignment covers Lecture # 07-15.
Deadline: The deadline to submit your assignment solution is 18-12-2020. Your assignment must be submitted within the due date through VU-LMS. No assignment will be accepted through email after the due date. -
Assignment No. 3
Semester: Spring 2020
CS201 – Introduction to Programming Total Marks: 20Due Date: 23/07/2020
Instructions
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:
To enable students to understand and practice the concepts of:
• Classes
• Objects
• Loops
• File handlingAssignment Submission Instructions
You have to submit only .cpp file on the assignments interface of CS201 at VULMS. Assignment submitted in any other format will not be accepted and will be graded zero marks.
Please note again, assignment submitted other than .cpp format will get zero marks.Assignment
Assignment Statement:
Assume you are working as a sports data analyst for a university named “ABC University”. Your job is to collect data of different players and judge their performance. Based on the data collected from players, their performance for a given season will be analyzed and comparison among players of the team will be made for selection. For this purpose, you are required to write a program in C++ that will create a class named “Sports”. The class will create a file named “Sample.txt” in the current directory. You will use file handling mechanism for entering player’s information. Following tasks are required:• You are required to create a class named “Sports”.
• Declare three data members of Sports class named playername, game_name and total_wins with appropriate data types.
• The class will consist of 6 functions named input_file(), read_file(), notstartingwithA(), lower(), upper() and digit() respectively along with a default constructor. The description of each function is given with the screenshots in the “Sample output”.
• In the main() function an object of the class “Sports” will be created and it will be used along with switch statement to call the functions mentioned above. i.e. input_file(), read_file(), notstartingwithA(), lower(), upper() and digit().
• Initially a menu will be displayed consisting of different choices as shown below:• User will enter a choice from the choices given in the menu. Output of each selected number is shown in the output samples below for detailed description.
Sample Output:-
1.
• In the first step the following menu will appear at the output screen.
• User will first populate file “Sample.txt” before reading the file as given below.
• The function named input_file() will take input from user and store it in the file named “Sample.txt”. If a user wants to enter second record, the first record in the file will not be deleted; rather new data will be added at the end of the file.
• The function read_file() will read all data stored in the file “Sample.txt” from start to end.
• The function notstartingwithA() will check the file and find all lines of the file “Sample.txt” that are not started with character “A” including blank lines. E.g. the above data will consists of 3 lines in the file. notstartingwithA() function will count all those line and display the count on output screen as given below.
• The function lower() will find all those lines that are started with lower characters in the file “Sample.txt” and display the count on outputs screen as given below.
• The function upper() will find all those lines that are started with an upper case character in the file “Sample.txt” and display the count on outputs screen as given below.
• The function digit() will find all those lines that are started with a digits in the file “Sample.txt” and display the count on output screen.
• Program will also check for invalid choices as given below.
Best of luck
Lectures Covered: (Lecture # 17- 27) and Solution Deadline: (23/07/2020).
-
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
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.
Write a menu in C++ which should show the country code and name at the start of application:
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 1095Sample 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. -
Re: CS201 Assignment 1 Solution and Discssion
Assignment No. 1Semester: Spring 2020
CS201 – Introduction to Programming Total Marks: 20Due Date: 01/06/2020
Instructions
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).Recommended tool to develop Assignment
Dev C++Objectives:
To enable students to understand and practice the concepts of:
• Data Types and Variables
• Arithmetic and Logical Operators
• If-else and switch case statementsAssignment Submission Instructions
You have to submit only.cpp file on the assignments interface of CS201 from your LMS account. Assignment submitted in any other format will not be accepted and will be scaled with zero marks.For any query related to assignment, please contact [email protected].
Assignment
Create a menu based program using C++ which will calculate the increment and tax deduction amount on salary based on the pay scale of an employee. After this, net salary of employee will be calculated. Details of these calculations are provided in Solution Guidelines.
You are required to use initial salary, increment rate, and tax deduction rate given in following table for each of the given pay scale.
Pay Scale Initial Salary Increment Rate Tax deduction Rate SPS6 40,000 20% 3% SPS7 60,000 15% 3% SPS8 80,000 10% 3% SPS9 100,000 5% 3%Solution Guidelines:
• There should be a menu consisting of different pay scales and options to select any one pay scale. See first sample screenshot for reference.
• On the basis of a selected pay scale, calculate increment amount and tax deduction amount. For the rate of increment and tax, use the table given above.
• Increment amount will be calculated through initial salary on the basis of given rate.
• Updated salary will be calculated as initial salary plus incremented amount.
• Tax deduction amount will be calculated through updated salary as per given rate.
• Formula to calculate net salary is Net Salary = Initial Salary – Incremented Amount – Tax Deduction Amount
• After doing all necessary calculations, display initial salary, incremented amount, increased (updated) salary, tax deduction amount and net salary. See last sample screenshot for reference.Sample Screenshots of Output:
Screenshot of menu.
Screenshot of selecting invalid choice of pay scale from menu.
Screenshot to display all calculated values on screen.
Lectures Covered: (Lecture # 1- and Due date to submit solution: (Monday, June 01, 2020).
-
Assignment No. 3
Semester: Fall 2019
CS201 – Introduction to Programming Total Marks: 20
Due Date: 15-01-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 make Class while dealing with real life problems
• How to associate functions with Class.
• How to implement switch statement for Class based functions.
• How to deal with file handling.
• How to manipulate already created file.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 with zero marks.Problem Statement
Press 1 to ADD AN EMPLOYEE. Press 2 to DISPLAY FILE DATA. Press 3 to INCREASE EMPLOYEE SALARY.
Write a console-based employee management system through binary File Handling (In order to observe data security, we use binary file format so that data cannot be read directly from the TXT file) which will perform management actions of Employee by taking input from user by showing following three options:
After dealing with each option, show prompt to user and continue the program until user press other than ‘y’Instructions to write C++ program:
Use Class Employee to declare all Employee’s belongings.
Make a EMPLOYEE.TXT file for saving Employee records
Each time program runs, check and delete EMPLOYEE.TXT file if already exists.
Switch statement will be implemented to perform multiple conditions and to perform different actions based on the conditions. i.e. Option 1, 2 and 3.
Write functions to perform tasks given in options.
Screenshots for Guidance:1 Initially when program executes, following screen will show to user to get input from the user.
2 If user press any other option then 1 at the first time i.e. without creating any file for Employees, then show error to user.
3 If User press 1, then take Employee credentials from user using prompt statements as follows and save that data in binary file named EMPLOYEE:
4 If User Press 2, then show all Employee Records to user by reading data from the file, which is depicted as follows:
5 If User press 3, then ask Employee code from user and then take amount of salary to be increased and update record of that Employee. depicted as follows:
Good Luck!
Lectures Covered: This assignment covers Lecture # 15-30.
Deadline: The deadline to submit your assignment solution is 15-01-2020. Your assignment must be submitted within the due date through VU-LMS. No assignment will be accepted through email after the due date. -
-
Cs201 current paper 14_12_2019 8:30am Q no.1 Convert the following while loop into a for loop Int I=1; While(i<=h) { Couti*I; I++; } Q no.2 Given below is the code segment of a file handling program. What is the purpose of the condition given in the while loop While(! Infile.eof()) { Infile>> name>>sal>>dept; Cout name"\ t" saal"\ t" dept endl; } Q no.3 Write a function definition which takes three arguments: retail price, sales taxes, incom tax and returns the net price of a book. Note: the net price of the book can be calculated by the formula Net price= retail price + sales tax + incom tax Q no.4 Write a program which defines two string " Hello" and "Pakistan", merges both the strings using manipulation function and display on the screen. Q no.5 What will be the output from the following program? #include<iostream> #include<conio.h> Int main ( ) { for int i=1; i<6;i++ If( i%2==0) Couti+1endl; else Coutiendl; System("pause"); }
-
Quiz 2 Total Questions : 10
Please read the following instructions carefully!
Quiz will be based upon Multiple Choice Questions (MCQs).You have to attempt the quiz online. You can start attempting the quiz any time within given date(s) of a particular subject by clicking the link for Quiz in VULMS.
Each question has a fixed time of 90 seconds. So you have to save your answer before 90 seconds. But due to unstable internet speeds, it is recommended that you should save your answer within 60 seconds. While attempting a question, keep an eye on the remaining time.
Attempting quiz is unidirectional. Once you move forward to the next question, you can not go back to the previous one. Therefore before moving to the next question, make sure that you have selected the best option.
DO NOT press Back Button / Backspace Button while attempting a question, otherwise you will lose that question.
DO NOT refresh the page unnecessarily, specially when following messages appear
Saving…
Question Timeout: Now loading next question…Javascript MUST be enabled in your browser; otherwise you will not be able to attempt the quiz.
If for any reason, you lose access to internet (like power failure or disconnection of internet), you will be able to attempt the quiz again from the question next to the last shown question. But remember that you have to complete the quiz before expiry of the deadline.
If any student failed to attempt the quiz in given time then no re-take or offline quiz will be held.
Start Quiz
-
Assignment No. 2
Semester: Fall 2019
CS201 – Introduction to Programming Total Marks: 20Due Date:
02-12-2019Instructions
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 random numbers.
• How to write user defined functions and pass an array to them as parameter.
• How to implement switch statement to process specific options.
• How to compare elements of array.
• How to find transpose of an array.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.An array of arrays is known as two-Dimensional array. In C++ it is also known as matrix. A matrix can be represented as a table of rows and columns. Like single dimensional arrays, we can store same type of data in it. Elements stored in array can be accessed using array index. Index starts from [0][0]. Means the index of row and column starts from 0. Following is an example of a two-dimensional array declaration and initialization having 3 rows and 3 columns.
int mularray[3][3] = { //Declaration and initialization of a 2D Array {1, 2, 3}, {5, 7, 9}, {0, 2, 4} }; // The value of mularray [0][0] is 1 // The value of mularray [0][1] is 2 // The value of mularray [1][2] is 9 // The value of mularray [2][1] is 2Problem Statement
Press 1 to populate a two-dimensional array with integers from 1 to 100. Press 2 to display the array elements. Press 3 to display the largest element present in the array along with its row and column index. Press 4 to find and show the transpose of the array.
Write an option-based program in C++ which should show following four options to the user at the start of application:
Instructions to write C++ program: Use random number function to populate the array i.e. rand( ). Range should be 1 to 100.
To populate the array poulateArray( ); To display all elements of Array showElements( ); To show largest element in the array showLargestElement( ); To show transpose of the array transposeArray( );
Hint: use srand( ) function before rand( ) to seed the random number. In loop, rand( ) may generate same numbers so you should use srand(time(0)) before rand( ) to generate different random numbers. To use time(0) you may need to include time.h header file.
Switch statement will be implemented to perform multiple conditions and to perform different actions based on the conditions. i.e. Option 1, 2, 3 and 4.
Write user defined functions to perform tasks given in options. Following function names should be used for consistency.Screenshots for Guidance:
1 If the user choses any option other than “1” at the start when the array is empty, the user should get a message like “Sorry the array is empty, first populate it by pressing 1 to perform this task ". See the following sample output:
2 Upon pressing 1, a message like “Array has been populated successfully!" should be displayed. See the following sample output:
3 Array elements should be displayed when the user presses 2. See the following screenshot for it:
4 Largest number along with its row and column number can be found by pressing 3. Similarly, if the user presses 4 transpose of the array should be displayed. See the sample outputs for both options:
Good Luck!
Lectures Covered: This assignment covers Lecture # 11-15.
Deadline: The deadline to submit your assignment solution is 02-12-2019. Your assignment must be submitted within the due date through VU-LMS. No assignment will be accepted through email after the due date. -
Assignment No. 1
Semester: Fall 2019
CS201 – Introduction to Programming Total Marks: 20Due Date: November 14, 2019
Instructions
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:
To enable students to understand and practice the concepts of:
• Variables and operators
• Loops or repetition structures
• If-else statements
• Functions
• Random number generation
• Control random number in specific rangeAssignment Submission Instructions
You have to submit only.cpp file on the assignments interface of CS201 at VULMS. Assignment submitted in any other format will not be accepted and will be graded zero marks.
Please note again, assignment submitted other than .cpp format will get zero marks.Assignment
Programming is a nice tool which can be used to make our life easier. With the help of programming we can do many things auto generated and efficiency. As a programmer first task of this semester is given to you is develop a console-based application for school teachers. This application will auto generate questions for Grades 1, 2, 3, 4 and 5. Using this application teacher will be able to give different paper to each student.
Assignment Statement:
Write a menu-based program in C++ that will take input from user(teacher) and fulfill following requirements.• There should be a menu that allow to select grade of class.
• Created questions should be mixed type (addition and subtraction).
• User will give number of questions that will be generated for a paper.
• Ratio of addition and subtraction questions is not fixed. It will random, a paper can have more questions of one type than other. See sample output screenshot.
• Number of minimum and maximum digits in paper of grade 1 will be two.
• Number of minimum and maximum digits in paper of grade 2 will be three.
• Number of minimum and maximum digits in paper of grade 3 will be four.
• Number of minimum and maximum digits in paper of grade 4 will be five.
• Number of minimum and maximum digits in paper of grade 5 will be six.
• Screen shot of required application is given below as simple output.
• Most critical requirement is, the operand (number) on left side of subtraction sign must be larger than the number on right side of sign (operator). This requirement is highlighted in sample screenshot too.
• In case of addition operation, the operand (number) on left side of addition sign can be larger or smaller from the number on right side of sign (operator).Solution instructions:
• Variables, loops, if-else, rand() function with % operator, functions (one which return a value and one which do not return a value) will help you to solve the problem.
• Use rand() function to generate a random number. You can control the range of number with the help of modulus (%) operator.
• To use rand() function you must include “stdlib.h” header file.
• To control the range of random number rand() % N can help, if value of N will be 100 then range of randomly generated number will be 0 to 99.
• If you want to control the range of random number between 10 to 19 then following formula will help.
o [10 + rand() % (19 – 10 + 1)]Sample output:
Lectures Covered: (Lecture # 1- 10) and Solution Deadline: (November 14, 2019).
-
Assignment No. 3 Semester: Spring 2019
CS201 – Introduction to Programming
Total Marks: 20Due Date: 11/07/2019
Instructions
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).Recommended software for assignment development:
Dev C++Objectives:
To enable students to understand and practice the concepts of:
• Variables and operators
• Loops / Repetition Structures
• Switch Statement
• Functions
• String Manipulation Functions
• StructuresAssignment Submission Instructions
You have to submit only .cpp file on the Assignments interface of CS201 at VULMS. Assignment submitted in any other format will not be accepted and will be graded with zero marks.Assignment
Problem:
struct Student { int student_id; char student_name[50]; float marks; }s[10];
Structures are used to overcome the shortcomings of arrays. Basically arrays are used to store more than one data values of a single datatype.
Ex : int a[100] stores integer datatype values
Whereas if you want to make students result database including student_id (int), student_name (char), marks (float) of more than one student, you cannot use array. Here comes the use of structures. Structures are user defined datatypes which allows you to store data of different types.
Example:Assignment Statement:
Write a menu based system in C++ for “Library Book Record System” that will take input from user for the following menu. You will create a structure and perform the following operations on the structure.
Press 1 To Enter a Book Record.
Press 2 To Display all Records of Books Available in Library.
Press 3 To Search Books by Author Name.
Press 4 To Count Total Books in Library.
Press 5 To Exit from the System.*System will take following inputs from user to enter a book record:
• Book ID
• Book Title
• Author of Book
• Cost of BookSolution Instructions:
Use switch statement for the menu based system.
You can use user defined functions for each of the task mentioned above to manage your code.*Note:
Restrict your system that it do not allow to add more than 5 books and on try of adding books more than limit show message i.e. “No more space in System for another book”.
Use strcmp function to search books by author name in Book_Author(); function.Sample output:
Lectures Covered: This assignment covers lectures 16 -25.
Deadline: The deadline to submit your assignment solution is Thursday, July 11, 2019. Your assignment must be submitted within the due date through VULMS. No assignment will be accepted through email after the due date.
SOLVED CS201 Assignment 2 Solution and Discussion
-
Re: CS201 Assignment 2 Solution and Discussion
Assignment No. 2
Semester: 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. -
@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"; }
-
code please?