Sie sind auf Seite 1von 7

Riffat batool(ID-150896)

150896@student.au.edu.pk
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:

cs.ahsan.shehzad@gmail.com

Das könnte Ihnen auch gefallen