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

New Presentation 1

Uploaded by

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

New Presentation 1

Uploaded by

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

WACHEMO UNIVERSITY(DURAME CAMPUS)

COLLEGE ENGINNERING AND TECHNOLOGY DEPARTIMENT


OF COMPUTER SCIENCE
COURSE TITLE :-COMPUTER PROGRAMMING(C++)
GROUP ASSIGNMENT

STUDENTS NAME ID
1. MULUALEM SEBA........................................................................1501157
2. TAGESSE ABATE............................................................................1501300
3. ISRAEL ABERA...............................................................................1500999

submitted to Ms. Lidiya Tadesse


submission date 03/08/2016 E.C
1. Write a program in C++ to find Size of fundamental data types. (char, short, int, long, long
long, float, double, long double, bool)

code output
#include<iostream>
using namespace std;
int main(){
cout<<"size of char :"<<sizeof(char)<< "byte"<<endl;
cout<<"size of int :"<<sizeof(int)<<"byte"<<endl;
cout<<"size of short :"<<sizeof(short)<<"byte"<<endl;
cout<<"size of long :"<<sizeof(long)<<"byte"<<endl;
cout<<"size of long long :"<<sizeof(long long)<<"byte"<<endl;
cout<<"size of float :"<<sizeof(float)<<"byte"<<endl;
cout<<"size of double :"<<sizeof(double)<<"byte"<<endl;
cout<<"size of long double :"<< sizeof(long double)<<"byte"<<endl;
cout<<"size of bool :"<<sizeof(bool)<<"byte"<<endl;
return 0;
}
2. Write a program in C++ to swap two numbers.
2.write a c++ program to swap two numbers

code
output
#include <iostream>
using namespace std;
int main()
{
int num1=6,num2=4,temp;
cout<<"before swapping :"<<endl;
cout<<"first number is"<<num1<<endl;
cout<<"second number is"<<num2<<endl;
temp=num1;
num1=num2;
num2=temp;
cout<<"after swapping"<<endl;
cout<<"first number is"<<num1<<endl;
cout<<"second number is"<<num2<<endl;

return 0;
}
3. Write a program in C++ to convert temperature in Fahrenheit to Kelvin.

output
code

#include<iostream>
using namespace std;
int main()
{
double fahrenheit,kelvin;
cout<<"Enter temperature in fahrenheit :";
cin>>fahrenheit;
kelvin=(fahrenheit-32)*5/9+273.15;
cout<<"temperature in kelvin"<<kelvin<<"k"<<endl;
return 0;
}
4. Write a C++ program to display the following by using for loop statement
(1, 1) (1, 2) (1, 3) (1, 4) (3, 1) (3, 2) (3, 3) (3, 4)

code output

#include<iostream>
using namespace std;
int main()
{
for(int i=1; i<=3; i+=2)
{
for(int j=1; j<=4; j++)
{
cout<<"("<<i<<" ,"<<j<<")";
}
}
cout<<endl;
return 0;
}
5. Write a program in C++ to compute the total and average of four numbers.

code
#include <iostream> output
using namespace std;
int main()
{
double average,total;
int num1,num2,num3,num4;
cout<<"Enter the four numbers";
cin>>num1>>num2>>num3>>num4;
{
total=num1+num2+num3+num4;
average=total/4;
}
cout<<"the total of the four numbers is :"<<total<<endl;
cout<<"the average of the four numbers is :"<<average;
return 0;
}
6. Write a program in C++ that takes a number as input and prints its multiplication table up
to 10.

code output

#include <iostream>
using namespace std;
int main()
{
double result,num;
cout<<"enter number :";
cin>>num;
for(int i=1;i<=10;i++)
{
result=num*i;
cout<<num<<" x "<<i<<" = "<<result<<endl;
}
return 0;
}
7. Write a program in C++ which accepts the user's first and last name and print them in
reverse order with a space between them.

code output
#include<iostream>
#include<string>
using namespace std;
int main()
{
string fristname,lastname;
cout<<"enter your fristname";
cin>>fristname;
cout<<"enter your lastname";
cin>>lastname;
cout<<"Name in reverse order "<<lastname<<" "<<fristname<<endl;
return 0;
}
8. Write a C++ program that display the following shape.
########
*******
&&&
*** output
1

code
#include<iostream>
using namespace std;
int main()
{
cout<<"########"<<endl;
cout<<"*******"<<endl;
cout<<"&&&"<<endl;
cout<<"***"<<endl;
cout<<"1"<<end;
return 0;
}
9. Write a C++ program to display the following vertically using while loop statement.10, 11, 13, 14, 16, 18, 19, 20

code
#include <iostream> output
using namespace std;
int main()
{
int i=10;
while(i<=20)
{
if(i==12||i==15||i==17)
goto increment;
cout<<i<<endl;
increment:
i++;
}
return 0;
}
10. Write a C++ program that display the following shape.
1
12
123
1234
12345
output

code
#include <iostream>
using namespace std;
int main()
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
cout<<j;
}
cout<<endl;
}
return 0;
}
11. Write a C++ program that display the following shape. 12345
1234
123
12
1
6

output
program(code)

#include<iostream>
using namespace std;
int main()
{
for(int i=5;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
cout<<j;
}
cout<<endl;
}
return 0;
12. Write a C++ program that display the following shapes
(a)
*
**
***
****
output
*****
****** program(code)
*******
******** #include <iostream>
********* using namespace std;
********** int main()
{
for(int i=1;i<=10;i++)
{
for(int j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}
return 0;
}
(b)
program(code) output
**********
********* #include <iostream>
******** using namespace std;
******* int main()
****** {
***** for(int i=1;i<=10;i++)
**** {
*** for(int j=i;j<=10;j++)
** {
* cout<<"* ";
}
cout<<endl;
}
return
(c)
program(code) output
**********
*********
******** #include <iostream>
******* using namespace std;
****** int main()
***** {
**** for(int i=1;i<=10;i++)
*** {
** for(int j=1;j<=i;j++)
* {
cout<<" ";
}
for(int j=i;j<=10;j++)
{
cout<<"* ";
}
cout<<endl;
}
return 0
(d)

program(code) output
*
** #include <iostream>
*** using namespace std;
**** int main()
***** {
****** for(int i=1;i<=10;i++)
******* {
******** for(int j=i;j<=10;j++)
********* {
********** cout<<" ";
}
for(int j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}
return 0;

You might also like