0% found this document useful (0 votes)
50 views

Assignment Itc 2

This document contains an assignment submission for a C++ programming course. It includes 8 questions with C++ code solutions. The questions cover topics like if/else conditional logic, loops, functions for calculating bonuses, checking leap years, reversing digits in a number, and other basic programming challenges. The submission includes the student's name, registration number, date and course details.

Uploaded by

Maaz Nasir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Assignment Itc 2

This document contains an assignment submission for a C++ programming course. It includes 8 questions with C++ code solutions. The questions cover topics like if/else conditional logic, loops, functions for calculating bonuses, checking leap years, reversing digits in a number, and other basic programming challenges. The submission includes the student's name, registration number, date and course details.

Uploaded by

Maaz Nasir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

FALL 2022

Course Code: CSCS1513


Course Title: LT
Assignment No.

Course instructor: Hina Tahir


Section: A-24
Program ITC

To be filled by students
Student name: MAAZ NASIR
Registration No: LIF22BSCS1051

Date of Submission: 4-12-2022


C++ Programs and Flowchar
Q.1

A company decided to give bonus of 5% to employee if his/her year of service is


more than 5 years. Ask user for their salary and year of service and print the net
bonus amount.

#include<iostream>

using namespace std;

int main ()

int service,salary,bonus;

cout<<"enter the salary:"<<endl;//user enter the salry.

cin>>salary;

cout<<"enter the service:"<<endl;//enter the service.

cin>>service;

if(service>5){

bonus=salary*5/100; //5 percent of salry.

salary=bonus+salary;

cout<<"total salary after bonus:"<<salary<<endl;

else{

cout<<"total salary without bonus:"<<salary;


}

return 0;

}
Q.2(a)
2. a) A student will not be allowed to sit in exam if his/her attendence is less than 75%. Take following
input from user Number of classes held Number of classes attended. And print percentage of class
attended Is student is allowed to sit in exam or not.

#include<iostream>

using namespace std;

int main ()

float classesattended, totalclasses, percentage;

cout<<"enter the total classes held:"<<endl;//user enter the total classes.

cin>>totalclasses;

cout<<"enter classes attended by student:"<<endl;//user will enter the classes.

cin>>classesattended;

if(classesattended<=totalclasses){
percentage=(classesattended/totalclasses)*100;//formula for percentage.

cout<<percentage <<"%" <<"of class attended" <<endl;

if(percentage<75 && percentage>=0){

cout << "Student is not allowed to sit in exam because his/her percentage is
below 75";

else

cout << "Student is allowed to sit in exam because his/her percentage is


above 75";

else{

cout<<"attended classes is not more than:";

return 0;

}
Q.2(b)
Modify the above question to allow student to sit if he/she has medical cause.
Ask user if he/she has medical cause or not ( 'Y' or 'N' ) and print accordingly.

#include<iostream>

using namespace std;

int main() {

float c , e;

cout<<"enter the total no. of classes held.\n";

cin>>c;

cout<<"enter the no. of classes attended.\n";

cin>>e;

if((e/c) * 100 < 75) {

cout<<"your attendance is less than 75%.\n";

char f;

cout<<"Do you have a medical cause? 'Y' for yes and 'N' for no.\n";

cin>>f;

switch(f) {

case 'y':

cout<<"you are eligible for giving the examinations.";

break;

case 'n':

cout<<"sorry, you are not eligible for giving the examinations.";

break;
default:

cout<<"Invalid input.";

} else {

cout<<"you are eligible for giving the examinations.";

return 0;

Q 4. If x = 2 y = 5 z = 0 then find values of the following expressions: a. x == 2 b. x


!= 5 c. x != 5 && y >= 5 d. z != 0 || x == 2 e. !(y < 10)

#include<iostream>

using namespace std;

int main() {

int x=2;

int y=5;

int z=0;

cout << (x == 2) << endl;// answer is (1).

cout << (x != 5) << endl;//answer is (1)

cout << ((x != 5) && (y >= 5)) << endl;//answer is 1.

cout << ((z != 0) || (x == 2)) << endl;//answer is 1

cout << !(y < 10) << endl;//answer is 0


return 0;

}
Q5. Write a program to check whether a entered character is lowercase ( a to z )
or uppercase ( A to Z ).

#include<iostream>

using namespace std;

int main() {

char ch;

cout<<"enter the character"<<endl;

cin>>ch;

if(ch>='A'&& ch<='Z'){

cout<<"character is uppercase""\n"<<ch<<endl;

else if (ch>='a'&& ch<='z'){

cout<<"character is lowercase" <<ch<<endl;

else{

cout<<"incorrect data";

return 0;

}
Q.6
Write a program to check if a year is leap year or not. If a year is divisible by 4
then it is leap year but if the year is century year like 2000, 1900, 2100 then it
must be divisible by 400
#include<iostream>

using namespace std;

int main()

int a;// Declaration of variables

cout<<"Enter the Year: ";// print message

cin>>a;

if((a%4==0) && (a%100!=0))// condition to check leap YEARS

cout<<a<<" is a Leap Year";

else if(a%400==0)// condition to check leap or CENTURY YEARS

cout<<a<<" is a Leap Year";

else// block of code to be executed if condition becomes false

cout<<a<<" is not a Leap Year";

return 0;

}
Q.7

Ask user to enter age, sex ( M or F ), marital status ( Y or N ) and then using
following rules print their place of service. if employee is female, then she will
work only in urban areas. if employee is a male and age is in between 20 to 40
then he may work in anywhere if employee is male and age is in between 40 t0
60 then he will work in urban areas only. And any other input of age should
print "ERROR".

#include<iostream>

using namespace std;

int main()

int age;

char gender,mstatus;

cout<<"enter age of his/her:"<<age<<endl;

cin>>age;

cout<<"enter the gender if male type ='M ' ,if female type='F':" <<gender
<<endl;

cin>>gender;

cout<<"enter meriatl status:Yes/NO "<<mstatus<<endl;

cin>>mstatus;

if(gender=='f'|| gender=='F'){
cout<<"she will work only in urban areas."<<endl;

if(gender=='m'|| gender=='M'){

if((age>=20)&&(age<=40)){

cout<<" he may work in anywhere:"<<endl;

else if((age>=40)&&(age<=60)){

cout<<" he will work in urban areas only:"<<endl;

else{

cout<<"input of age should print 'ERROR' ";

return 0;

}
Q8. A 4 digit number is entered through keyboard. Write a program to print a
new number with digits reversed as of original one. E.g.- INPUT : 1234 OUTPUT :
4321 INPUT : 5982 OUTPUT : 289

#include<iostream>

using namespace std;

int main()

int Num,reverse;

cout<<"enter the number:";

cin>>Num;

while(Num>0){

reverse=Num%10;

cout<<reverse;

Num=Num/10;

return 0 ;

You might also like