Skip to content

CS201 - Introduction to Programming

3 Topics 56 Posts
  • CS201 Assignment 3 Solution and Discussion

    Solved cs201 assignment 3 solution discussion spring 2020
    5
    0 Votes
    5 Posts
    2k Views
    zaasmiZ
    CS201 ASSIGNMENT 3 SOLUTION SPRING 2021 #include <iostream> using namespace std; #define PI 3.14159265 class Circle { private: double radius; public: void setRadius(); void computeAreaCirc(); Circle(); ~Circle(); }; Circle::Circle() { radius = 0.0; } void Circle::setRadius() { radius = 5.6; } void Circle::computeAreaCirc() { cout << "Area of circle is: " << PI * (radius * radius) << endl; cout << "Circumference of circle is: " << 2 * PI * radius << endl; } Circle::~Circle() { } class Rectangle { private: double length; double width; public: void setLength(); void setWidth(); void computeArea(); Rectangle(); ~Rectangle(); }; Rectangle::Rectangle() { length = 0.0; width = 0.0; } void Rectangle::setLength() { length = 5.0; } void Rectangle::setWidth() { width = 4.0; } void Rectangle::computeArea() { cout << "Area of Rectangle: " << length * width << endl; } Rectangle::~Rectangle() { } main() { cout<<"********************SCIENTIFIC CALCULATOR********************"<<endl; cout<<""<<endl; int run = 1; string option, choice; while(run) { cout << "\nOPTION 1 for computing Area and Circumference of the circle" << endl; cout << "OPTION 2 for computing Area of the Rectangle" << endl; cout << "Select your desired option(1-2): "; cin >> option; if(option == "1") { Circle nCircle; nCircle.setRadius(); nCircle.computeAreaCirc(); cout << "Do you want to perform anyother calculation(Y/N):"; cin >> choice; if(choice == "Y" || choice == "y") { continue; } else { break; } } else if(option == "2") { Rectangle nRectangle; nRectangle.setLength(); nRectangle.setWidth(); nRectangle.computeArea(); cout << "Do you want to perform anyother calculation(Y/N):"; cin >> choice; if(choice == "Y" || choice == "y") { continue; } else { break; } } else { cout << "Invalid Option!, Option should be from (1-2)" << endl; } } }
  • CS201 Assignment 2 Solution and Discussion

    Solved assignment 2 cs201 discussion solution spring 2020
    3
    0 Votes
    3 Posts
    1k Views
    zaasmiZ
    @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"; }
  • 0 Votes
    4 Posts
    2k Views
    cyberianC
    #include <iostream> #include <stdlib.h> using namespace std; main() { int choice = 0, salary = 0; float increment = 0.0, tax = 0.0, newsal = 0.0; cout<<"\n ********* SALARY CALCULATOR *********\n"<<endl; cout<<" *************************************\n"<<endl; cout<<" ********* Enter 1 for SPS6 *********\n"<<endl; cout<<" ********* Enter 2 for SPS7 *********\n"<<endl; cout<<" ********* Enter 3 for SPS8 *********\n"<<endl; cout<<" ********* Enter 4 for SPS9 *********\n"<<endl; cout<<" Select a pay scale from the menu: "; cin>>choice; switch(choice){ case 1: salary = 40000; increment = salary * 20/100; newsal = salary + increment; tax = newsal * 3/100; break; case 2: salary = 60000; increment = salary * 15/100; newsal = salary + increment; tax = newsal * 3/100; break; case 3: salary = 80000; increment = salary * 10/100; newsal = salary + increment; tax = newsal * 3/100; break; case 4: salary = 100000; increment = salary * 5/100; newsal = salary + increment; tax = newsal * 3/100; break; default: cout<<" Selected choice is invalid."<<endl<<endl; } if(choice >= 1 && choice <=4) { cout<<" Initial Salary: "<<salary<<endl; cout<<" Incremented Amount: "<<increment<<endl; cout<<" Increased Salary: "<<newsal<<endl; cout<<" Tax Deduction: "<<tax<<endl; cout<<" Net Salary: "<<newsal-tax<<endl<<endl; } system("pause"); }
Reputation Earning
How to Build a $1,000/Month World CUP LIVE Matches Live Cricket Streaming
Ads
File Sharing
Stats

0

Online

3.0k

Users

2.8k

Topics

8.5k

Posts
Popular Tags
Online User
| |