0% found this document useful (0 votes)
39 views9 pages

Tutorial Assignment 3

The document contains a series of C++ programming questions and their respective solutions. Each question demonstrates different programming concepts such as conditional statements, switch cases, and basic arithmetic operations. The code snippets include functionality for determining leap years, handling user input, and calculating pay based on hours worked.

Uploaded by

Ibn E Shukran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views9 pages

Tutorial Assignment 3

The document contains a series of C++ programming questions and their respective solutions. Each question demonstrates different programming concepts such as conditional statements, switch cases, and basic arithmetic operations. The code snippets include functionality for determining leap years, handling user input, and calculating pay based on hours worked.

Uploaded by

Ibn E Shukran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Name : Asfandyar

Reg No # : BCS 193105


Question 1:
#include<iostream>
using namespace std;
int main()
{
int year; cin >> year;
if (year % 100 == 0 && year%400 ==0)
cout << "Leap Year" << endl;
else
cout << "Not Century Year" << endl;
system("PAUSE");
return 0;
}

Question 2:
#include<iostream>
using namespace std;
int main()
{
char code; cout << "Input Code " << endl; cin >> code;
switch (code)
{
case 'A':
cout << "Admin Block" << endl;
break;
case 'B':
cout << "Buisness Block" << endl;
break;
case 'C':
cout << "CS Block" << endl;
break;
case 'c':
cout << "CS Block" << endl;
break;
case'D':
cout << "Conference Hall" << endl;
break;
default :
cout << "Sorry Does Not Exist" << endl;
}
system("PAUSE");
return 0;
}

Question 3:
#include<iostream>
using namespace std;
int main()
{
int x, y; cout << "Input x : " << endl; cin >> x;
if (x > 7)
y = 1;
else if (x < 5)
{
if (x < 3)
y = 2;
else
y = 3;
}
else
y = 4;
cout << "x = " << x <<" y = " << y << endl;
system("PAUSE");
return 0;
}

Question 4:
#include <iostream>
using namespace std;
int main()
{
char x;
cout << "Enter Input = ";
cin >> x;
if (x >= 48 && x <= 57)
cout << "Input is A Digit " << endl;
else if (x >= 65 && x <= 90)
{
cout << "Input is Alphabet = " << x << endl;
cout << "Alphabet is Uppercase " << endl;
}
else if (x >= 97 && x <= 122)
{
cout << "Input is Alphabet = " << x << endl;
cout << "Input is Lowercase" << endl;
}
else
cout << "Input is Neither A Digit Nor An Alphabet " << endl;
system("PAUSE");
return 0;
}

Question 5:
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
cout << "Enter Number 1 and Number 2 respectively : " << endl;
cin >> num1 >> num2;
switch (num1 == num2)
{
default :
{
switch (num1 > num2)
{
case 1:
{
cout << "Number 1 is Greater = " << num1 << endl;
switch (num1 % 2 == 0)
{
case 1:
cout << "Number is Even " << endl;
break;
default:
cout << "Number is Odd " << endl;
break;
}
break;
}
default:
{
cout << "Number 2 is Greater = " << num2 << endl;
switch (num2 % 2 == 0)
{
case 1:
cout << "Number is Even" << endl;
break;
default:
cout << "Number is Odd" << endl;
break;
}
}
}
break;
}
case 1:
cout << "Invalid Input" << endl;
break;
}
system("PAUSE");
return 0;
}
Question 6:
#include <iostream>
using namespace std;
int main()
{
int pay, rate, hour;
cout << "Input Pay,Rate and Hours respectively : " << endl;
cin >> pay >> rate >> hour;
pay = rate * hour;
if (hour > 40)
{
pay = pay+(hour - 40) * 1.5 * rate;
cout << "Pay = " << pay << endl;
}
else
{
cout << "Pay = " << pay << endl;
}
system("PAUSE");
return 0;
}
Question 7:
#include <iostream>
using namespace std;
int main()
{
int num1, square, cube;
cout << "Input Number : ";
cin >> num1;
if (num1 % 2 == 0)
{
square = num1 * num1;
cube = num1 * num1 * num1;
cout << "Square = " << square << endl;
cout << "Cube = " << cube << endl;
}
else
{
cout << "Number is odd ";
}
system("PAUSE");
return 0;
}

You might also like