www.vustudents.ning.com

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

# CS201 Introduction to Programming Assignment No 02 Fall 2020 Solution / Discussion Due Date: 18-12-2020

CS201 Introduction to Programming Assignment No 02 Fall 2020 Solution / Discussion Due Date: 18-12-2020

 Assignment No.  2Semester: 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:

1. Press 1 for Florida.
2. Press 2 for Georgia.
3. Press 3 for Michigan.
4. 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

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.

Views: 1605

### Replies to This Discussion

cs201 assignment no 02 solution fall 2020 codes

#include <iostream>

#include <stdlib.h>

#include <conio.h>

using namespace std;

void showElements();

void PercentageBiden();

void PercentageTrump();

void PercentageJorgensen();

void line();

float per[4];

unsigned long vote[3][5] = {

{ 1, 5284453, 5658847, 70046, 110133462},

{ 2, 2465781, 2455428, 61894, 4983103},

{ 3, 2790648, 2644525, 60287, 5495460},

};

int main()

{

int option;

showElements();

opt:

{

Opt:

{

cout "\n\nPress the states code to calcalculate percentage of Trum, Biden and Jorgensen Votes" endl;

cout "Press 1 for Florida." endl;

cout "Press 2 for Georgia." endl;

cout "Press 3 for Michigan." endl;

cout "Press 4 for Exit." endl;

cout "\n\nPlease Select an Option, use numbers from 1 to 4 :   ";

cin >> option;

}

switch (option)

{

case 1:

line();

PercentageBiden();

{

cout "\nPercentage of Jo Biden votes is: " per[1] endl;

cout "\nPercentage of Donald Trump votes is: " per[2] endl;

cout "\nPercentage of Jo Jorgensen votes is: " per[3] endl;

goto opt;

}

break;

case 2:

line();

PercentageTrump();

{

cout "\nPercentage of Jo Biden votes is: " per[1] endl;

cout "\nPercentage of Donald Trump votes is: " per[2] endl;

cout "\nPercentage of Jo Jorgensen votes is: " per[3] endl;

goto opt;

}

break;

case 3:

line();

PercentageJorgensen();

{

cout "\nPercentage of Jo Biden votes is: " per[1] endl;

cout "\nPercentage of Donald Trump votes is: " per[2] endl;

cout "\nPercentage of Jo Jorgensen votes is: " per[3] endl;

goto opt;

}

break;

case 4:

return(0);

break;

default:

{

cout "\n\nChoice should be Between 1 to 4 " endl;

cout "\nInvalid Choice, Please Select again: " endl;

goto opt;

}

}

system("Pause");

}

}

void showElements()

{

int b, c;

for (b = 0; b < 3; b++)

{

for (c = 0; c < 5; c++)

cout vote[b][c] "\t\t";

cout endl;

}

}

void PercentageBiden()

{

int b;

for (b = 1; b < 4; b++)

per[b] = float(vote[0][b]) / 11013346.0 * 100;

}

void PercentageTrump()

{

int b;

for (b = 1; b < 4; b++)

per[b] = float(vote[1][b]) / 4983103.0 * 100;

}

void PercentageJorgensen()

{

int b;

for (b = 1; b < 4; b++)

per[b] = float(vote[2][b]) / 5495460.0 * 100;

}

void line()

{

cout "\n--------------------------------------------";

}

# CS201 Assignment 2 Solution

CS201 Assignment 2 Solution
Please watch video once even if you have submitted assignment. i mentioned some points which may help you. Most of students submitted wrong solution.
For sake of your marks watch my video

1

2

3

4

5

## Latest Activity

Hira and Sana Shah are now friends
1 hour ago
1 hour ago
1 hour ago
1 hour ago
2 hours ago
AbdulRabecca and Wasim joined + M.Tariq Malik's group

### PAD603 Governance, Democracy and Society

2 hours ago
Raja Ashyan joined + M.Tariq Malik's group

### CS314 Introduction to Cellular Networks

2 hours ago
AbdulRabecca liked Hira's profile
2 hours ago