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

C++ Assignment (Mulualem and ... )

The document contains 12 programming problems assigned as a group assignment. The problems cover basic C++ concepts like data types, operators, loops, functions, arrays and printing patterns. Students are required to write C++ code to solve each problem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

C++ Assignment (Mulualem and ... )

The document contains 12 programming problems assigned as a group assignment. The problems cover basic C++ concepts like data types, operators, loops, functions, arrays and printing patterns. Students are required to write C++ code to solve each problem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

WACHEMO UNIVERSITY (DURAME CAMPUS)

College Engineering and Technology


Department of Computer Science
Computer Programming
Group Assignment
Academic Year 2016 E
Name ID
1,Mulualem Seba.................... 1501157
2.Tagesse abate …………………….1501300
3.Israel Abera …………………………1500999

1. Write a program in C++ to find Size of fundamental data types. (char, short, int, long, long
long, float, double, long double, bool)

#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.

#include <iostream>

using namespace std;


int main()
{
double num1=5,num2=10;
cout<<"before swap\n";
cout<<"num1 = "<<num1<<endl;
cout<<"num2 = "<<num2<<endl;
num1=num1+num2;
num2=num1-num2;
num1=num1-num2;
cout<<"after swap\n";
cout<<"num1 = "<<num1<<endl;
cout<<"num2 = "<<num2<<endl;

return 0;
}

1
3. Write a program in C++ to convert temperature in Fahrenheit to Kelvin.

#include<iostream>
using namespace std;
double fahrenheittokelvin(double fahrenheit)
{
double kelvin=(fahrenheit - 32) * 5/9 + 273.15;
return kelvin;
}
int main()
{
double fahrenheit;
cout<<" enter temperature in fahrenheit";
cin>>fahrenheit;
double kelvin=fahrenheittokelvin(fahrenheit);
cout<<"temperature in kelvin"<<kelvin<<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)

#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;

2
5. Write a program in C++ to compute the total and average of four numbers.

#include <iostream>

using namespace std;


int main()
{
double average,total=0,num[4];
for(int i=0;i<4;i++)
{
cout<<"Enter num"<<i+1<<":";
cin>>num[i];
total+=num[i];
}

cout<<"the total of the four numbers is :"<<total<<endl;


cout<<"the average of the four numbers is :"<<total/4;

return 0;
}

6. Write a program in C++ that takes a number as input and prints its multiplication table up
to 10.

#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;
}

3
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.

#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.

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

4
9. Write a C++ program to display the following vertically using while loop statement.10, 11,
13, 14, 16, 18, 19, 20

#include <iostream>
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

#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

5
#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)
*
**
***
****
*****
******
*******
********
*********
**********
#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;
}

6
(b)
**********
*********
********
*******
******
*****
****
***
**
*
#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 0;
}

7
(c)
**********
*********
********
*******
******
*****
****
***
**
*
#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;
}

8
(d)
*
**
***
****
*****
******
*******
********
*********
**********
#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