1.
The Farming Problem:
In this problem, a person is
asking you to tell him how many legs can be counted among all his animals. The
farmer has given three types sample:
A.)
Chicken: 2 legs
B.)
Cows: 4 legs
C.)
Goat : 4 legs
The farmer has counted his animals and he gives you a
subtotal for each sample. You have to implement a function in OOP that returns
the total number of legs of all the animals.
Rules: Don’t for get to return the result. Remember that the farmer wants to now the
total number of legs and not the total number of animals.
Hints:
Farmer said that total number of animals is:
150
Farmer mentioned that there are 100
chickens, 25 cows and 25 goats
#include
ReplyDeleteusing namespace std;
class B
{
public:
int g,c,ck,total=0;
void getsubtotal()
{
cout<<"Enter the total number of animals for each category: "<>g>>c>>ck;
}
int countleg(int gl,int cl,int ckl)
{
total= g*gl + c*cl + ck*ckl;
return total;
}
};
int main()
{
B obj;
obj.getsubtotal();
obj.countleg(4,4,2);
cout<<"The total number of legs are: "<<obj.total<<endl;
}
#include
ReplyDeleteusing namespace std;
class B
{
public:
int i,cn=0;
char a[10];
void inp()
{
cout<<"Enter the string:";
cin>>a;
cout<<a;
for(i=0;a[i]!='\0';i++)
{
cn++;
}
}
};
int main()
{
B obj;
obj.inp();
cout<<"number of characters:"<<obj.cn<<endl;
}
#include
ReplyDeleteusing namespace std;
class B
{
public:
int g,c,ck,total=0;
void getsubtotal()
{
cout<<"Enter the total no of animals for each catagory:"<>g>>c>>ck;
}
int countleg(int gl,int cl,int ckl)
{
total=g*gl+c*cl+ck*ckl;
return total;
}
};
int main()
{
B obj;
obj.getsubtotal();
obj.countleg(4,4,2);
cout<<"The total number of legs are :"<<obj.total<<endl;
}
#include
ReplyDeleteusing namespace std;
class B
{
public:
int g,c,ck,total=0;
void getsubtotal()
{
cout<<"Enter the total number of animals for each category: "<>g>>c>>ck;
}
int countleg(int gl,int cl,int ckl)
{
total= g*gl + c*cl + ck*ckl;
return total;
}
};
int main()
{
B obj;
obj.getsubtotal();
obj.countleg(4,4,2);
cout<<"The total number of legs are: "<<obj.total<<endl;
}