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

PROGRAMMINGGROUP1ASS

This document contains the solutions to programming assignments submitted by a student. It includes programs to display shapes like rectangles and diamonds, programs that perform mathematical operations on integers, programs that evaluate conditional statements, programs that display formatted output, programs to convert between Celsius and Fahrenheit temperatures, and programs to calculate circle properties and swap integer values.

Uploaded by

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

PROGRAMMINGGROUP1ASS

This document contains the solutions to programming assignments submitted by a student. It includes programs to display shapes like rectangles and diamonds, programs that perform mathematical operations on integers, programs that evaluate conditional statements, programs that display formatted output, programs to convert between Celsius and Fahrenheit temperatures, and programs to calculate circle properties and swap integer values.

Uploaded by

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

GROUP 1

Assignment 1

NAME ID. NO DEPT.


FEVEN ADEFRIS ECS/1427/23 CS
BETELHEM W/YOHANS ECS/1430/23 CS
WUBALEM AYELE ECS/144/22 CS
TIZTA BIRRU EAR/1313/22 ARCH

sub date
sub to
1. Write a program that displays the following figures
a. Rectangle
ANS;
#include<iostream>
using namespace std;
int main() {
cout<<"* * * * * *"<<"\n* *"<<"\n* *"<<"\n* *"<<"\n* * * * * *" ;
return 0;
}

(f) diamond
---ANS;---
#include<iostream>
using namespace std;
int main(){
cout<<" *"<<"\n ***"<<"\n *****"<<"\n *******"<<"\n*********"<<"\n
*******"<<"\n *****"<<"\n ***"<<"\n *";
return 0;
}

2. Write a program that accepts two integers x and y and displays the result of the following operations
a. x+y c. x*y e. x/y g. x<y
b. x-y d. x%y f. x>y h. x==y

ANS:

#include<iostream>
using namespace std;
int main()
{
int x,y;
cout<<"\n enter the values of the two numbers x and y: ";
cin>>x>>y;
cout<<"The sum of the two numbers is: "<<x+y<<endl;
cout<<"The difference of the two numbers is: "<<-y<<endl;
cout<<"The product of the two numbers is: "<<x*y<<endl;
cout<<"The modulus of the two numbers is: "<<x%y<<endl;
cout<<"The division of the two numbers is: "<<x/y<<endl;
cout<<"Is x greater than y? "<<(x>y)<<endl;
cout<<"Is x less than y? "<<(x<y)<<endl;
cout<<"Is the value of x and y equal? "<<(x==y);
return 0;
}
3. let x=5,y=4 and s=3
a. if z=(x>y) and t= ( x==y) what will be the out puts of
i. z&&t iii. !z
ii. z||t

---ANS:----
i.the output is 0 iii. the output is 0
ii.the output is 1

b. if z=(x*s>y*y) , t= ( x*4>=y*s) and what will be the out puts of


i. z&&t
ii. z||t
iii.!z

--ANS.---
i. the output is 0 iii. the output is 1
ii. the output is 1

4. What will be the outputs of the following program segment?


int x=4,y=6;
cout<<++x<<endl; ANS. OUTPUT
cout<<y--<<endl; 5
z=y + x++; 6
cout<<z--<<endl; 10
cout<<x<<endl; 6
cout<<y--<<endl; 5
cout<<z<<endl; 9
cout<<y<<end 4

5. Write a program that displays the following


a. No. Name Age
__________________

1. Abebe 35
2. Selam 24
3. Rahel 18
4. Gadissa 30
b. The statement Addis Ababa which means “New flower” is the capital city of Ethiopia

---ANS:(a)---
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
cout<<"\nNo."<<setw(8)<<"Name"<<setw(13)<<"Age";
cout<<"\n------------------------";
cout<<"\n1."<<setw(10)<<"Abebe"<<setw(11)<<"35";
cout<<"\n2."<<setw(10)<<"Selam"<<setw(11)<<"24";
cout<<"\n3."<<setw(10)<<"Rahel"<<setw(11)<<"18";
cout<<"\n4."<<setw(12)<<"Gadissa"<<setw(9)<<"30";
cout<<endl;
return 0;
}
---Ans(b)-----
#include<iostream>
using namespace std;
int main(){
cout<<"Addis Ababa which means \"New flower\" is the capital city of Ethiopia";
return 0;
}
6. Write a program that
a. Accepts temperature in degree Celsius and converts it into degree Fahrenheit
---ANS---.
#include<iostream>
using namespace std;
int main() {
double c,f;
cout<<"enter the temperature in degree fahrenheit: ";
cin>>f;
c=(f-32.0)*5.0/9.0;
cout<<"temperature in degree celsius is: "<<c;
return 0;
}
ii. and also, from Fahrenheit to Celsius
#include<iostream>
using namespace std;
int main() {
double c,f;
cout<<"enter the temperature in degree celsius: ";
cin>>c;
f=(c*1.8)-32;
cout<<"temperature in degree fahrenheit is: "<<f;
return 0;
}
b. Accepts radius of a circle and display its area and circumference
#include<iostream>
using namespace std;
int main() {
const double pie=3.1415169;
double A,C,r;
cout<<"\nenter the radius of the circle";
cin>>r;
A=pie*(r*r);
C=2*pie*r;
cout<<"The area of the circle with the radius of "<<r<<" is:"<<A<<endl;
cout<<"The circumference of the circle with the radius of "<<r<<" is: "<<C;
return 0;
}
g. Accepts two integers and swaps their value
ANS.

#include<iostream>
using namespace std;
int main() {
int a,b;
cout<<"enter the two numbers";
cin>>a>>b;
cout<<"before swapping a is "<<a<<" and b is " <<b<<endl;
a=a+b;
b=a-b;
a=a-b;
cout<<"after swapping a is "<<a<<" and b is " <<b<<endl;
return 0;
}

---------------------------------------//-----------------------------------------------------

You might also like