ADD









class problem 20-09-18


 Programing C++ CSC 284 Sec: D and E
1. Write a program following bellow points
i. Take a class Solver; private data will be integer
type -a, sum, i, j, x, r, count; 5 public functions will be-void solve1(), void
solve2(), void solve3(), void solve4(), void solve5().
ii. void solve1() will find out bellow pattern, 1 22 333
4444
iii. void solve2() will find out the floyd’s triangle, 1 2 3
4 5 6 7 8 9 10
iv. void solve3() will find out factorial with user input,
v. void solve4() will find out the average of 3 inputs,
vi. void solve6() will find out the summation of those
numbers who are not divisible by 5 between 100 to 250.
vii. Take a main function and create proper object to call
your required function.


#include<iostream>
using namespace std;
class Solver
{
public:
void solve1();
void solve2();
void solve3();
void solve4();
void solve5();
};
void Solver::solve1()
{
int i,j;
for(i=1;i<=4;i++){
for(j=1;j<=i;j++)
{
cout<<i;
}
cout<<endl;
}
}
void Solver::solve2()
{
int i,j,z=1;
for(i=1;i<=4;i++){
for(j=0;j<i;j++){
cout<<z<<" ";
z++;
}
cout<<endl;
}
}
void Solver::solve3()
{
int a,z=1,i;
cin>>a;
for(i=1;i<=a;i++){
z=z*i;}
cout<<z<<endl;
}
void Solver::solve4()
{
int i,j,z,avg;
cin>>i>>j>>z;
avg=((i+j+z)/3);
cout<<avg<<endl;
}
void Solver::solve5()
{
int i,z=0;
for(i=100;i<=250;i++){
if(i%5==0){
continue;
}
z=z+i;
}
cout<<z<<endl;
}
int main()
{
int a;
Solver ob;
cin>>a;
switch(a){
case 1:
cout<<"this is pattern"<<endl;
ob.solve1();
break;
case 2:
cout<<"this is floyed's triangle"<<endl;
ob.solve2();
break;
case 3:
cout<<"Enter a number to get its factorial"<<endl;
ob.solve3();
break;
case 4:
cout<<"enter 3 value to get average"<<endl;
ob.solve4();
break;
case 5:
cout<<"this is summation of those number :"<<endl;
ob.solve5();
break;
}
}


No comments

Theme images by lishenjun. Powered by Blogger.