Skip to content

CS201 - Introduction to Programming

3 Topics 56 Posts
  • 1 Votes
    2 Posts
    2k Views
    cyberianC
    https://youtu.be/PAY5DTXtq1A
  • 0 Votes
    8 Posts
    7k Views
    cyberianC
    modules:composer.user_said_in, @cyberian, CS201 Assignment 1 Solution and Discussion Write a C++ program that performs the following tasks: 1-Print your name and VU id. 2-Add last 3 digit of your VU id. 3-Display the result of sum on screen. 4-Use if-else statement :: a) If sum is odd then print your name using while loop. Number of iterations of while loop should be equal to the sum. b) If sum is even then print your VU id using while loop. Number of iterations of while loop should be equal to the sum. [use remainder operator on sum value to determine the odd and even value for if condition] For example, suppose the student id is BC123456781. Then by adding last 3 digits of vu id, we get 16 which is an even number. In this case, program should print your VU ID for 16 times using while loop. // C201 Assignment No: 1 Fall2021 #include <iostream> #include <string> using namespace std; void printnameid(string studentid, string studentname); int calculatelastthreedigits(string studentid); int main() { string studentid="bc123456789"; string studentname="ZAHID"; printnameid(studentid,studentname); int TotalLastThreeDigits=calculatelastthreedigits(studentid); int counter=1; int a,b,c; a=6; b=4; c=0; cout<<"Sum of Last Three Numbers ="<<a+b+c; cout<<"\n\n"; if ( TotalLastThreeDigits % 2 == 0) // Divide by 2 and see if the reminder is zero? then it is even otherwise it is odd number { cout << "the sum is an even value: \n\n"; cout<<"++++++++++++++++++++++++++++++++++++++++++++ \n\n"; while(counter <= TotalLastThreeDigits) { cout << " Iteration: " << counter << "\n"; cout << "My student id is:" << studentid << "\n"; counter++; } } else { cout << "the sum is an odd value: \n\n"; while(counter <= TotalLastThreeDigits) { cout << " Iteration: " << counter << "\n"; cout << "My name is " << studentname << "\n"; counter++; } } return 0; } void printnameid(string studentid, string studentname){ cout<<"My name is " << studentname << "\n\n\n"; cout<<"My student id is:" << studentid << "\n\n\n"; } int calculatelastthreedigits(string studentid) { int end=studentid.length(); // Ending point that is total length of string int start=end-3; // Starting point string lastthreedigits=studentid.substr(start,end); // Trim the last three digits; int total=0; //Calculate the sum of last three digits for ( int index=0; index < lastthreedigits.length(); index++) { total += lastthreedigits[index] - '0'; } return total; // return the total to calling statement. }
  • 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
| |