dear its 4th assignment we need 5th assignment which problem statement is also mention above(multiplying two arrays)so plz do it today is last date plzzzz
CS201 Introduction to ProgrammingView more random threads:
- ISL201 Assignment 1 Spring 2010 Solution May 10
- Object Oriented Programming (CS304) Assignment No.1 last...
- CS610 Computer Networks Assignment No 3 Solution Fall...
- MCM401 Fundamentals of Public Relations Assignment No. 01...
- CS304 Object Oriented Programming Assignment No 4 Solution...
- Assignment No. 2 MTH 301 (Fall 2010)
- Leadership and Team Management (MGMT623) Assignment No. 1...
- asign _1.data,struct
- FIN722 Assignment No 1 Fall 2014 Solution and Discussion...
- SOC101 Introduction to Sociology Assignment No 01 8th...
Assignment 4 Solution
Due Date:15/07/2010
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
Solution
#include <iostream.h>
#include <conio.h>
#include <string>
using std::string;
class Student{
private:
string name;
long rollNumber;
string semester;
double cgpa;
Sponsored Links
public:
Student(string nam,long roll,string stu,double cgp )
{
name=nam;
rollNumber=roll;
semester=stu;
cgpa=cgp;
}
Student()
{
name="";
rollNumber=0;
semester="Spring 2010";
cgpa=4.0;
}
string get_semester()
{
return semester;
}
void set_semester(string n)
{
semester=n;
}
void set_roll(long n)
{
rollNumber=n;
}
long get_roll()
{
return rollNumber;
}
void set_name(string n)
{
name=n;
}
string get_name()
{
return name;
}
void set_cgpa(double n)
{
cgpa=n;
}
double get_cgpa()
{
return cgpa;
}
void print()
{
cout<<"Student Information\n\n\n";
cout<<"Name: "<<name<<endl<<endl;
cout<<"Roll number: "<<rollNumber<<endl<<endl;
cout<<"Semester: "<<semester<<endl<<endl;
cout<<"Current GPA: "<<cgpa<<endl<<endl<<endl;
}
};
int main()
{
Student y;
Student z
("Orail",123456789,"Spring 2010",3.97);
y.print();
z.print();
system("pause");
return 0;
getch ();
}
dear its 4th assignment we need 5th assignment which problem statement is also mention above(multiplying two arrays)so plz do it today is last date plzzzz
There are currently 1 users browsing this thread. (0 members and 1 guests)