PDA

View Full Version : CS201 assignment #5



usman malik
07-11-2010, 07:16 AM
Problem Statement: Multiplication of two objects of same class
• You are required to write a class. Class should have an array of 10 integers as its private data member.
Class should have
• A default constructor which will initialize all array elements with zero.
• Getter and setter functions
• An operator overloading function which will overload * operator for this class.

 You are required to create three objects of the same class.
 You must assign values to first and second objects through setter functions. You can either take input arrays from user or use hard coded values.
 Display the values of first and second object through getter functions.
 Multiply both objects and store the result of multiplication in third object.
 Multiplication means the 1st element of member array of object1 should be multiplied by 1st element of member array of object2. Similarly, 2nd element should be multiplied with 2nd and so on. In the end, display the result stored in third object.
 Your program should support the statement like a = b * c, where a, b and c are objects of the same class.

-------------------------------------------------------------------------
Sample output:
Object 1 :
1
2
3
4
5
6
7
8
9
10

Object 2 :
10
9
8
7
6
5
4
3
2
1

Multiplication of both objects :
10
18
24
28
30
30
28
24
18
10

plz give me solution.............

viki
07-12-2010, 01:57 PM
what is the dua date aur jab bhi assignment for solution upload karoo to also mention the dua date of it

usman malik
07-13-2010, 06:29 AM
15th july sir

digger303
07-15-2010, 05:22 PM
#include<iostream.h>

class multiply
{
private:
int myarry[10];
public:
//Constructor initializing array for all four objects of class!
multiply()
{

for(int i=0;i<=9;i++)
{
myarry[i]=0;
}

}
//returns values of objects a and b on the screen
void getter(multiply a,multiply b)
{
cout<<"Values for object a are:-"<<endl;
for(int t=0;t<=9;t++)
{

cout<<"Value"<<"."<<t<<"\t"<<a.myarry[t]<<endl;
}
cout<<"Values for object b are:-"<<endl;

for(int s=0;s<=9;s++)
{
cout<<"Value"<<"."<<s<<"\t"<<b.myarry[s]<<endl;
}


}

//takes values from user for objects a and b
void setter(multiply x,multiply y,multiply z)
{

cout<<"Enter values in array for object a"<<endl;

for(int m=0;m<=9;m++)
{
cout<<"Value Please?"<<endl;
cin>>x.myarry[m];
}
cout<<"Enter values in array for object b"<<endl;

for(int n=0;n<=9;n++)
{
cout<<"Value Please?"<<endl;
cin>>y.myarry[n];
}
getter(x,y);
calculate(x,y,z);

}




//performs the multiplication
void calculate(multiply a,multiply b,multiply c)

{
for(int bee=0;bee<10;bee++)

{

c.myarry[bee]=a.myarry[bee]*b.myarry[bee];

}
result(c);

}

//outputs result
void result(multiply f)

{
cout<<"Your Result is"<<endl;

for(int h=0;h<10;h++)
{

cout<<h<<"-"<<f.myarry[h]<<endl;
}

}




};

void main()
{
multiply o,a,b,c;

o.setter(a,b,c);
}

sanam
07-15-2010, 05:24 PM
itna lamba solution yah app nay khud banaya hai?

M.Ali
01-31-2011, 10:38 PM
ye to galt hy

Xpert
02-01-2011, 01:35 AM
galat hai tu bhai app is ko thake ker den

techaholic
02-01-2011, 01:48 AM
everyone shud instead thank him for uploading it
and jisko lagta hai k kuch ghalat hai either he shud ammend it himself or shud make it right for him [acha hai u will get extra marks for correction while rest nerds will get poor:) so gud for u]

thank u xpert:)

Xpert
02-02-2011, 12:10 AM
welcome dear.

mohsin33
02-02-2011, 04:41 PM
/* ID: MC100402622.
Name: M.MOHSIN CH.
*/


#include <iostream.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <fstream.h>
using namespace std;


class crectangle
{
private:
int itop;
int iright;
int ibot;
int ileft;

public:

static int irefcount;
// default constructor is declared below.
crectangle ();
// copy constructor is declared below.
crectangle (crectangle &, crectangle *);
// destructor is declared below.
~crectangle ();

// methods are declared below.
int getrectanglearea (crectangle &);
void getitop();
void getiright();
void getibot();
void getileft();
void getirefcount();
void setmembrs (int,int,int,int);
void setitop(int);
void setiright(int);
void setibot(int);
void setileft(int);

};

// Methods, constructor and destructor are defined below.

// crectangle () is defined below.
crectangle::crectangle ()
{
itop=0;
iright=0;
ibot=0;
ileft=0;
irefcount++;
}// crectangle ()'s defination ends here.

// crectangle (crectangle &) is defined below.
crectangle::crectangle(crectangle &a, crectangle *pointer)
{
pointer=new crectangle;
pointer->itop=a.itop;
pointer->iright=a.iright;
pointer->ibot=a.ibot;
pointer->ileft=a.ileft;
irefcount++;
}

// destructor ~crectangle () is defined below.
crectangle::~crectangle()
{
irefcount--;
}// ~crectangle ()'s defination ends here.

// getitop () is defined below.
void crectangle:: getitop()
{
cout<<endl<<"Value of ITop is: \t"<<itop<<endl;
}// getitop ()'s defination ends here.

// getiright() is defined here.
void crectangle:: getiright()
{
cout<<endl<<"Value of IRight is: \t"<<iright<<endl;
}// getiright()'s defination ends here.

// getibot () is defined below.
void crectangle:: getibot()
{
cout<<endl<<"Value of IBot is: \t"<<ibot<<endl;
}// getibot ()'s defination ends here.

// getileft () is defined below.
void crectangle:: getileft()
{
cout<<endl<<"Value of ILeft is: \t"<<ileft<<endl;
}// getileft ()'s defination ends here.

// getirefcount () is defined here.
void crectangle:: getirefcount()
{
cout<<endl<<"Value of IREfcount is: \t"<<irefcount<<endl;
}// getirefcount()'s defination ends here.

// getrectangleare () is defined below.
int crectangle::getrectanglearea(crectangle &a)
{
return (a.itop * a.iright * a.ibot * a.ileft);

}// getrectanglearea ()'s defination ends here.

// setmembers (int, int ,int ,int ) is defined below.
void crectangle:: setmembrs(int a, int b, int c, int d)
{
itop=a;
iright=b;
ibot=c;
ileft=d;
} // setmembers ()'s defination ends here.


// setitop (int) is defined below.
void crectangle::setitop(int a)
{
itop=a;
}//setitop (int) ends here.

// setiright (int) ends here.
void crectangle:: setiright (int b)
{
iright=b;
}// setiright (int)'s defination ends here.

// setibot(int) is defined below.
void crectangle::setibot(int c)
{
ibot=c;
}//setbot (int)'s defination ends here.

// setileft(int) is defined below.
void crectangle::setileft(int d)
{
ileft=d;
}// setileft(int)'s defination ends here.



// Static member of class is intialized here.
int crectangle::irefcount=0;

// Main () function starts from here.
main ()
{
int a, b, c, d =0;
crectangle *pointer;
crectangle rectangle1, rectangle2;
a=6;
b=13;
c=14;
d=5;
cout<<endl;
rectangle1.setitop(a);
rectangle1.setiright(b);
rectangle1.setibot(c);
rectangle1.setileft(d);
cout<<"Area of rectangle1 is: \t"<<rectangle1.getrectanglearea(rectangle1)<<endl;
a=3;
b=10;
c=8;
d=20;
rectangle2.setmembrs(a,b,c,d);
cout<<endl<<"Area of rectangle2 is: \t"<<rectangle1.getrectanglearea(rectangle2)<<endl;
cout<<endl<<"The Number of Rectangles is \t"<<crectangle::irefcount<<endl;
crectangle(rectangle1,pointer);
cout<<endl<<"After using copy-constructor Number of Rectangles is \t"<<crectangle::irefcount<<endl;
delete pointer;
cout<<endl<<"The Number of Rectangles is \t"<<crectangle::irefcount<<endl;

}