0% found this document useful (0 votes)
62 views7 pages

Lab 2 Riffat

This document contains code snippets and explanations for several C++ programs using cout statements to output text and numbers. It includes 4 questions with code answers. Question 1 has 4 parts showing different output patterns using cout. Question 2 takes input of 3 numbers, finds the highest and lowest, and calculates their sum and difference. Question 3 takes a number as input and checks if it is positive or negative.

Uploaded by

Danish Azhar
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)
62 views7 pages

Lab 2 Riffat

This document contains code snippets and explanations for several C++ programs using cout statements to output text and numbers. It includes 4 questions with code answers. Question 1 has 4 parts showing different output patterns using cout. Question 2 takes input of 3 numbers, finds the highest and lowest, and calculates their sum and difference. Question 3 takes a number as input and checks if it is positive or negative.

Uploaded by

Danish Azhar
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/ 7

Riffat batool(ID-150896)

[email protected]
Air University, Islamabad
Department of Computer Science
Computer Programming
22dWeek Worksheet
..

Eclipse Configuration + Use of cout Statement

Question no. 01:


a):
Write C++ Programs to show the following using cout Statement:

My Name is
-------

My name is ------Department of Computer


Science

Co

#include <iostream>
using namespace std;

Cod

#include <iostream>
using namespace std;

cout<<"My name is Riffat


Batool"<<endl;

int main() { cout<<"My name is Riffat


Batool"<<endl;
cout<<"Department of
ComputerScience"<<endl;
cout<<"Air University
Islamabad"<<endl;
cout<<"Programming is my
Passion"<<endl;

return 0;
}

return 0;
}

int main() {

b):

Write C++ Programs to show the following using cout Statement:

*
***
*****
*******
*********

*
***
*****

Code:

Code:

#include <iostream>
using namespace std;
int main() {

cout<<"*"<<endl;
cout<<"***"<<endl;
cout<<"*****"<<endl;
cout<<"*******"<<endl;
cout<<"*********"<<endl;
return 0;

#include <iostream>
using namespace std;
int main() {
cout<<"
*"<<endl;
cout<<"
***"<<endl;
cout<<"
*****"<<endl;
cout<<" *******"<<endl;
cout<<"*********"<<endl;
return 0;
}

c):
Write C++ Programs to show the following using cout Statement:

********
********
********

* * *
* * * * *

Cod

Code:

#include <iostream>
using namespace std;

#include <iostream>
using namespace std;

int main() {

int main() {
cout<<" * "<<endl;
cout<<" *** "<<endl;
cout<<"***** "<<endl;
cout<<" *** "<<endl;
cout<<" * "<<endl;

cout<<"********"<<endl;
cout<<"********"<<endl;
cout<<"********"<<endl;

return 0;
}
return 0;
}

d):
Write C++ Programs to show the following using cout Statement:

Main Manu
_____________
1. Option 1
2. Option 2
3. Option 3

*************
* Welcome
*

Code:

Code:

#include<iostream>
Using namespace std;

#include <iostream>
using namespace std;
int main() {

int main() {
cout<<"*************"<<endl;
cout<<"Main Menu"<<endl;

cout<<"*

WELCOME

*"<<endl;

cout<<"_________"<<endl;
cout<<"*************"<<endl;
cout<<"1.Option1"<<endl;
cout<<"2.Option2"<<endl;
cout<<"3.Option3"<<endl;
return 0;

return 0;
}

Question no. 02:


Write a program which takes input of three values from user of integer type,
calculate
Sum and difference of the highest and smallest value among the three and
display on screen.
Code:
#include <iostream>
using namespace std;
int main()
{
int v1, v2, v3, greater, smaller,sum,diff;
cout<< "enter value 1" <<endl;
cin>> v1;
cout<< "enter value 2" <<endl;
cin>> v2;
cout<< "enter value 3" <<endl;
cin>> v3;
greater = v1;
if ((v2 > v1) && (v2 > v3))
{
greater = v2;
};
if ((v3 > v2) && (v3 > v1))
{
greater = v3;
};
cout<< "greater value is " << greater <<endl;
smaller = v1;
if ((v2 < v1) && (v2 < v3))
{
smaller = v2;
};
if ((v3 < v2) && (v3 < v1))
{
smaller=v3;
}
cout<< "smallest value is " << smaller <<endl;
sum=greater+smaller;
cout<<"sum is:"<<sum<<endl;
diff=greater-smaller;
Question
no. 03:

Write a program which takes input of one value from user, identify if the
value entered

is negative or positive. If the value entered is negative, convert it to positive


and display on screen.

Code:

#include <iostream>
using namespace std;
int main() {
int value;
cout<<"enter value : "<<endl;
cin>>value;
if(value>0)
{
cout<<"value is positive"<<endl;
}
else
{
cout<<"value is negative"<<endl;
}

return 0;
}

Subjectbscs-B-ID-Name-LabWeek-02
Send:

[email protected]

You might also like