CS201 Introduction to Programming Assignment No 02 Fall 2020 Solution / Discussion Due Date: 18-12-2020
Assignment No. 2 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:
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:
Source data: (Use two dimensional array to store following data)
[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.
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. |
Tags:
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;
cout "\nSource Data:\nStates\t\tBiden Votes\tTrump Votes\tJorgensen Votes\tTotalVotes\n";
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--------------------------------------------";
}
© 2021 Created by + M.Tariq Malik.
Powered by
Promote Us | Report an Issue | Privacy Policy | Terms of Service
We are user-generated contents site. All product, videos, pictures & others contents on site don't seem to be beneath our Copyrights & belong to their respected owners & freely available on public domains. We believe in Our Policy & do according to them. If Any content is offensive in your Copyrights then please email at m.tariqmalik@gmail.com with copyright detail & We will happy to remove it immediately.
Management: Admins ::: Moderators
Awards Badges List | Moderators Group
All Members | Featured Members | Top Reputation Members | Angels Members | Intellectual Members | Criteria for Selection
Become a Team Member | Safety Guidelines for New | Site FAQ & Rules | Safety Matters | Online Safety | Rules For Blog Post