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

Lab 4

This lab report submitted by Irtaza Ali Nasir to Sir Asad contains the solutions to 3 questions using C++ programming concepts like loops, conditional statements, and input/output functions. The first question involves creating a basic calculator using switch statements. The second question corrects a program to print asterisks in a nested loop pattern. The third question displays a pattern using nested while loops as instructed. For each question, the assigned code is provided along with the output displayed on the screen.

Uploaded by

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

Lab 4

This lab report submitted by Irtaza Ali Nasir to Sir Asad contains the solutions to 3 questions using C++ programming concepts like loops, conditional statements, and input/output functions. The first question involves creating a basic calculator using switch statements. The second question corrects a program to print asterisks in a nested loop pattern. The third question displays a pattern using nested while loops as instructed. For each question, the assigned code is provided along with the output displayed on the screen.

Uploaded by

Irtaza Ali Nasir
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

2020

LAB REPORT #4

SUBMITTED TO : SIR ASAD


SUMBITTED BY IRTAZA ALI NASIR

REG #NO . 200901099


QNO 1 Write a program to create a simple Calculator using the switch
Statement. Include +,-,*,/,%as basic operations, input will be two numbers
and based upon choice of user it will perform the operations. In case user
inputs invalid operator display “Please Select Valid Operator”.

#include<iostream>
#include<string>
using namespace std;
int main()
{
char s;
int a, b ,c;
cout << " ENTER VALUE OF a" << endl;
cin >> a ;
cout << " ENTER VALUE OF b" << endl;
cin >> b;
cout << "ENTER A OPREATION THAT YOU WANT TO PERFORM" << endl;;
cin >> s;
switch (s)
{
case '+' :
cout << "REQUIRED ANSWER" << endl;
cout << a + b;
break;
case '-':
cout << "REQUIRED ANSWER" << endl;
cout << a - b;
break;
case '*':
cout << a * b;
cout << "REQUIRED ANSWER" << endl;
break;
case '/':
cout << "REQUIRED ANSWER" << endl;
cout << a / b;
break;
case '%' :
cout << "REQUIRED ANSWER" << endl;
cout << a % b ;
break;
default :
cout << "Please Select Valid Operator" << endl;
}

}
RESULT ON SECREEN
QNO.02 Correct the following program who prints a sterick sign (*) in such a
way using nested while loops.

ASSINGED PROGRAM

#include <iostream>
using namespace std;
int main()
{
int i = 15, j = 15;
while (i > 0)
{
j = i - 1;
while (j > 0)
{
cout << "*";
j = j - 1;
}
cout << "\n";
i = i - 1;
}
system("pause");
return 0;
}
RESULT ON SECREEN

#include <iostream>
using namespace std;
int main()
{
int i = 1;
int l = 1;
while (i <= 10)
{
int r = 1;
while (r <=l )
{
cout << l;
if (l > 1)
{
cout << "==";
}
l--;
r++;
}
l = i + 1;
cout << "\n";
i++;
}
system("pause");
return 0;
}
QNO.3 A program to show the following using the nested while loop
ASSINGED PROGRAM :

RESULTS ON SECREEN :

#include <iostream>
using namespace std;
int main()
{
int i = 1;
int l = 1;
while (i <= 10)
{
int r = 1;
while (r <=l )
{
cout << l;
if (l > 1)
{
cout << "==";
}
l--;
r++;
}
l = i + 1;
cout << "\n";
i++;

You might also like