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

Ahadcs Assignment

Uploaded by

Abdul Ahad Khan
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)
27 views6 pages

Ahadcs Assignment

Uploaded by

Abdul Ahad Khan
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/ 6

2021

CS101 Lab
SUBMITTED BY: Abdul Ahad Khan
REGISTRATION NUMBER: 2021005
Class Section: CS101-F
“On my honor, as a student of Ghulam Ishan Khan Institute of Engineering Sciences and
Technology, I have neither given nor received unauthorized assistance on this academic
work.”

TASK1:
Write a function named times Ten. The function should have an integer parameter named
number. When times Ten is called, it should display the product of number times ten.(Note:
Do not just write the function. Write a complete program.)
#include<iostream>
using namespace std;
int ten(int num)
{ return (num*num*num*num*num*num*num*num*num*num); }
int main()
{ int a,r;
cout<<"ENTER NUMBER"<<endl;
cin>>a;
r=ten(a);
cout<<r;
return 0; }
TASK2
Write a function asks the user to enter the radius of the circle and then returns that number
as a double. Write another function that takes this radius as input and returns the area of
circle.
#include<iostream>
using namespace std;
int radius_ofcircle(int a)
{ return (a*2); }
float area_ofcircle(float b)
{ return (b*b*3.14); }
int main()
{ int radius,result;
cout<<"ENTER RADIUS OF CIRCLE"<<endl;
cin>>radius;
result=radius_ofcircle(radius);
cout<<result;
cout<<" "<<endl;
float c,d;
cout<<"ENTER RADIUS OF CIRCLE TO CALCULATE AREA"<<endl;
cin>>c;
d=area_ofcircle(c);
cout<<d;
return 0; }

TASK3
Write a value returning function that receives three integers and returns the largest of the
three. Assume the integers are not equal to one another.
#include<iostream>
using namespace std;
int largest_number(int a, int b, int c)
{ if(a>b && a>c)
{ return a; }
else if(b>a && b>c)
{ return b; }
else
{ return c; } }
int main()
{ int num1,num2,num3,x;
cout<<"ENTER FIRST NUMBER"<<endl;
cin>>num1;
cout<<"ENTER SECOND NUMBER"<<endl;
cin>>num2;
cout<<"ENTER THIRD NUMBER"<<endl;
cin>>num3;
x=largest_number(num1,num2,num3);
cout<<x;
return 0; }

TASK4
Write a function which converts an uppercase letter ‘A’{‘Z’ to the corresponding lowercase
letter. If the parameter is not a letter it must be returned unchanged. Write a main program
which calls the function.
#include<iostream>
using namespace std;
char change_letter(char ch)
{ if( ch!='A'|| ch!='B' || ch!='C' || ch!='D' || ch!='E' || ch!='F' || ch!='G'|| ch!='H' || ch!
='I'||ch!='J'||ch!='K'||ch!='L'||ch!='M'||ch!='N'||ch!='O'||ch!='Q'||ch!='R'||ch!='S'||ch!
='T'||ch!='U'||ch!='V'||ch!='W'||ch!='X'||ch!='Y'||ch!='Z' )
{ return (ch+32); } }
int main()
{ char x,y;
cout<<"ENTER ALPHABET"<<endl;
cin>>x;
y=change_letter(x);
cout<<y;
return 0; }
TASK5
Write a program will ask the user to enter the width and length of a rectangle and then
display the rectangle’s area. The program calls the following functions:
1. getLength-This function should ask the user to enter the rectangle’s length and then
return that value as a double.
2. getWidth-This function should ask the user to enter the rectangle’s width and then
return that value as a double.
3. getArea-This function should accept the rectangle’s length and width as arguments
and return the rectangle’s area. The area is calculated by multiplying the length by the
width.
4. displayData-This function should accept the rectangle’s length, width, and area as
arguments and display them in an appropriate message on the screen.

#include<iostream>
using namespace std;
int getLength(int a)
{ return (a*2); }
int getWidth(int b)
{ return (b*2); }
int getArea(int a, int b)
{ int c;
c=a*b;
return (c); }
int displaydata(int a,int b,int c)
{ return (a,b,c); }

int main()
{ int e,f,g,h,i;
cout<<"ENTER LENGTH:"<<endl;
cin>>e;
cout<<"ENTER WIDTH:"<<endl;
cin>>f;
g=getLength(e);
h=getWidth(f);
cout<<"DOUBLE LENGTH:\n"<<g<<endl;
cout<<"DOUBLE WIDTH:\n"<<h<<endl;
i=getArea(e,f);
cout<<"AREA:\n"<<i<<endl;
return 0; }

You might also like