<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CS201 Assignment 2 Solution and Discussion]]></title><description><![CDATA[<p dir="auto">Re: <a href="/topic/675/cs201-assignment-2-solution-and-discssion/">CS201 Assignment 2 Solution and Discussion</a></p>
<pre><code>Assignment No.  2
</code></pre>
<p dir="auto">Semester: Spring 2020<br />
CS201 – Introduction to Programming	Total Marks: 20</p>
<p dir="auto">Due Date:<br />
16-6-2020</p>
<p dir="auto">Instructions<br />
Please read the following instructions carefully before submitting assignment:<br />
It should be clear that your assignment will not get any credit if:</p>
<p dir="auto">o	Assignment is submitted after due date.<br />
o	Submitted assignment does not open or file is corrupt.<br />
o	Assignment is copied (From internet/students).</p>
<p dir="auto">Software allowed to develop Assignment</p>
<ul>
<li>Dev C++</li>
</ul>
<p dir="auto">Objectives:<br />
In this assignment, the students will learn:<br />
•	How to fill / populate a two-dimensional array using given source data.<br />
•	How to write user defined functions and pass an array to them as parameter.<br />
•	How to use if statement and do while loop.<br />
•	How to calculate the percentage in elements of array.<br />
•	How to display array elements.</p>
<p dir="auto">Assignment Submission Instructions<br />
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.</p>
<p dir="auto">Problem Statement<br />
Write a menu in C++ which should show the country code and name at the start of application:</p>
<ol>
<li>Press 0 for Pakistan.</li>
<li>Press 1 for China.</li>
<li>Press 2 for Italy.</li>
<li>Press 3 for UK.</li>
<li>Press 4 for Iran.</li>
<li>Press 5 for France.</li>
<li>Press 6 for Turkey.</li>
<li>Press 7 to exit.<br />
Instructions to write C++ program:</li>
</ol>
<p dir="auto">	Write functions to calculate % of recovered  patients,  % of deaths  in specific country . Following function names should be used for consistency.</p>
<table class="table table-bordered table-striped">
<tbody>
<tr>
<td>To display all elements in matrix form</td>
<td>showElements( );</td>
</tr>
<tr>
<td>Percentage of death</td>
<td>PercentageDeath ( ):</td>
</tr>
<tr>
<td>Percentage of recovered</td>
<td>PercentageRecovered();</td>
</tr>
</tbody>
</table>
<p dir="auto">Source data:</p>
<table class="table table-bordered table-striped">
<tbody>
<tr>
<td>Country Code</td>
<td>Total Cases</td>
<td>Total Deaths</td>
<td>Total Recovered</td>
</tr>
<tr>
<td>0</td>
<td>560,433</td>
<td>22,115</td>
<td>32,634</td>
</tr>
<tr>
<td>1</td>
<td>156,363</td>
<td>19,899</td>
<td>34,211</td>
</tr>
<tr>
<td>2</td>
<td>84,279</td>
<td>10,612</td>
<td>0</td>
</tr>
<tr>
<td>3</td>
<td>82,160</td>
<td>3,341</td>
<td>77,663</td>
</tr>
<tr>
<td>4</td>
<td>71,686</td>
<td>4,474</td>
<td>43,894</td>
</tr>
<tr>
<td>5</td>
<td>56,956</td>
<td>1,198</td>
<td>3,446</td>
</tr>
<tr>
<td>6</td>
<td>5,374</td>
<td>93</td>
<td>1095</td>
</tr>
</tbody>
</table>
<p dir="auto">Sample Output:<br />
First, user will call the showElements() method to display all the data in matrix form:<br />
Then, it will display a menu to calculate the percentage of dead and recovered persons for specific country:</p>
<p dir="auto"><img src="https://i.imgur.com/fHwRsBS.png" alt="f0a03ad3-d28d-412c-a2d8-e73dcc7d35da-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">If user presses 0 then it will show the percentage of dead and recovered persons for Pakistan:<br />
<img src="https://i.imgur.com/qmEICKY.png" alt="be43d8d9-feaf-4fd8-be53-2d0e0b95a0d3-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">If user presses 1 then it will show the percentage of dead and recovered persons for China:<br />
<img src="https://i.imgur.com/kGrQrkU.png" alt="9daeed49-a07e-4ee4-86a7-cb0af8f44ade-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">If the user enters option other then 0 to 7. Following messages display:<br />
Choice should be between 0 and 7<br />
Invalid choice, please select again:<br />
<img src="https://i.imgur.com/doqB6cU.png" alt="ba8aa527-baf7-4930-94f4-969cdfa62456-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Good Luck</p>
<p dir="auto">Lectures Covered:  This assignment covers Lecture # 11-15.<br />
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.</p>
]]></description><link>https://community.secnto.com//topic/1932/cs201-assignment-2-solution-and-discussion</link><generator>RSS for Node</generator><lastBuildDate>Mon, 08 Jun 2026 21:39:10 GMT</lastBuildDate><atom:link href="https://community.secnto.com//topic/1932.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 17 Jun 2020 08:55:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CS201 Assignment 2 Solution and Discussion on Wed, 17 Jun 2020 09:07:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zaasmi" aria-label="Profile: zaasmi">@<bdi>zaasmi</bdi></a> said in <a href="/post/5428">CS201 Assignment 2 Solution and Discussion</a>:</p>
<blockquote>
<p dir="auto">code please?</p>
</blockquote>
<pre><code>#include&lt;iostream&gt;
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&lt;&lt;"\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&lt;&lt;"\nPress the country code to calculate percentage of dead and recovered persons\n";
		cout&lt;&lt;"\n*** Press 0 for Pakistan ***";
		cout&lt;&lt;"\n*** Press 1 for China ***";
		cout&lt;&lt;"\n*** Press 2 for Italy ***";
		cout&lt;&lt;"\n*** Press 3 for UK ***";
		cout&lt;&lt;"\n*** Press 4 for Iran ***";
		cout&lt;&lt;"\n*** Press5 for France ***";
		cout&lt;&lt;"\n*** Press 6 for Turkey ***";
		cout&lt;&lt;"\n*** Press 7 to Exit ***";	
		cout&lt;&lt;"\n\nPlease select an option use number from 0 to 7 : ";
		input:
		cin&gt;&gt;user_choice;
		if(user_choice&gt;=0 &amp;&amp; user_choice&lt;=6)
		{
			PercentageDeath(source_data, user_choice);
			PercentageRecovered(source_data, user_choice);
		}
		else if(user_choice&lt;0 || user_choice&gt;7) 
		{
			cout&lt;&lt;"\n\nChoice should be between 0 to 7 ";
			cout&lt;&lt;"\ninvalid choice ! please select again : ";
			goto input;	
		}
	}while(user_choice!=7);
}

// definition of function showElements
void showElements(long s[][4])
{
	cout&lt;&lt;"Source Data : \n\n";
	cout&lt;&lt;"Country\tCases\tDeaths\tRecovered\n\n";
	for(int i=0; i&lt;7; i++)
	{
		for(int j=0; j&lt;4; j++)
		{
			cout&lt;&lt;s[i][j]&lt;&lt;"\t";
		}
		cout&lt;&lt;"\n";
	}
}

// definition of function PercentageDeath
void PercentageDeath(long s[][4], int i)
{
	float d_rate=(float)100*s[i][2]/s[i][1];
	cout&lt;&lt;"\nPercentage of death is "&lt;&lt;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&lt;&lt;"\n\nPercentage of recocered is "&lt;&lt;r_rate&lt;&lt;"\n";
}



</code></pre>
]]></description><link>https://community.secnto.com//post/5429</link><guid isPermaLink="true">https://community.secnto.com//post/5429</guid><dc:creator><![CDATA[zaasmi]]></dc:creator><pubDate>Wed, 17 Jun 2020 09:07:07 GMT</pubDate></item><item><title><![CDATA[Reply to CS201 Assignment 2 Solution and Discussion on Wed, 17 Jun 2020 08:57:48 GMT]]></title><description><![CDATA[<p dir="auto">code please?</p>
]]></description><link>https://community.secnto.com//post/5428</link><guid isPermaLink="true">https://community.secnto.com//post/5428</guid><dc:creator><![CDATA[Raazia Gul]]></dc:creator><pubDate>Wed, 17 Jun 2020 08:57:48 GMT</pubDate></item></channel></rss>