0% found this document useful (0 votes)
31 views6 pages

Lab Practice 1 - Com - Prog1

The document contains instructions and code snippets for 8 programming exercises. Students are asked to complete incomplete code, fix errors, run the programs, and upload the code and output to a Google Drive folder. The programs demonstrate basic C++ concepts like input/output, arithmetic operators, if/else statements, and a simple calculator program.

Uploaded by

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

Lab Practice 1 - Com - Prog1

The document contains instructions and code snippets for 8 programming exercises. Students are asked to complete incomplete code, fix errors, run the programs, and upload the code and output to a Google Drive folder. The programs demonstrate basic C++ concepts like input/output, arithmetic operators, if/else statements, and a simple calculator program.

Uploaded by

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

Lab practice 1 – Com.

prog1
Run all programs in your PC. Some codes are incomplete. Try to complete the code, fix the error and
run the code. After then upload all codes including the output screen in the “Google drive Folder for
Submitting Activity”. (It’s only for your Practice. I will not give you ant grade. I will check your code in
the VC time)

PROGRAM 1 :

#include <iostream>
using namespace std;
int main()
{
int a = 30;
int b = 12;
int sum = a + b;
cout << sum;
return 0;
}

ANS : 42

PROGRAM :2

int main()
{
int a = 30;
int b = 12;
int c = a + b;

cout << c;

return 0;
}

PROGRAM 3:

#include <iostream>
using namespace std;

int main()
{
int a, b;
cout << "Enter a number a\n";
cin >> a;
cout << "Enter number b\n";
cin >> b;
int sum=a+b;
cout <<a<< "+" << b << "=";
cout <<sum;
}

OUTPUT :

#include <iostream>
using namespace std;

int main()
{
int a;
cout <<"Enter a number please\n";
cin>>a;

int b;
cout <<"Enter another number or same number\n";
cin>>b;

int sum
sum =a+b;
cout <<"Sum is " <<sum <<endl;
return 0;
}

PROGRAM 4:

With this code, the program will ask the user to input their age.

#include <iostream>
using namespace std;

int main()
{
int age;
cout << "Please enter your age \n";
cin >> age;
if (age > 14) {
if(age >= 18) {
cout << "Adult";
}
else {
cout << "Teenager";
}
}
else {
if (age > 0) {
cout << "Child";
}
else {
cout << "Something's wrong";
}
}

return 0;
}

PROGRAM 5:

Here it is the code for for a very simple calculator:

Play with it and try to make it more fun.....

#include <iostream>

using namespace std;

int main()
{
cout << "Welcome To a very Basic calculator"<< endl;

cout << "Enter the first number: ";

int fnum;

cin>> fnum;
cout << "Enter the second number: ";

int snum;

cin>> snum;

cout<< "\nIf you want to \n Add the numbers Press 1 \n Press 2 to multiply \n Press 3 to divide\n
Press 4 to minus ";

int input;

cin >> input;


if(input==1){

cout<< "Your answer is: "<<fnum+snum;

}else if(input==2){
cout<< "Your answer is: "<<fnum*snum;

}else if(input==3){
cout<< "Your answer is: "<<fnum/snum;

}else if(input==4){
cout<< "Your answer is: "<<fnum-snum;
}
}

PROGRAM 6:

#include <iostream>
using namespace std;

int main()
{
int x = 10 * 2;
int y = 10 + 10;
int z = 10 - 5;
int a = 10 / 2;
int b = 10 % 1;

int sum;
sum << x+y+z+a+b;
cout << "Result is \n";
cout << x+y+z+a+b;
return 0;
}

//Output is 50

PROGRAM 7:

#include <iostream>
using namespace std;
int main()
{
int a, b, pro=a*b;
cout << "Enter a number \n";
cin >> a; cout << a <<endl;
cout << "Enter another number \n";
cin >> b; cout << b << endl;
cout << "The product is \n";
cout << pro;
return 0;
}

PROGRAM 8: Write a program. Output is followed

Output

Please Enter 1st Number! =

Please Enter 1st Number! =

Please Select Operation to Perform!

For Addition +

For Subtraction –

For Multiplication *

For Division /

For Modulo %

You might also like