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:
- PHY101 Physics Solution Fall Discuss about Assignment No 2...
- PHY301 Circuit Theory Assignment No .3 Solution Fall 2013
- MTH302 - Business Mathematics & Statistics Solution 11...
- CS101 Introduction to copmputer Assignment # 4 is uplode...
- CS605 Assignment 3 Spring 2010 May 14,2010
- IT430 Assignmnet No. 3
- Assignment 5 Of MTH202 (Spring 2010)
- CS701 Theory of Computation Assignment No. 1 Fall 2014 7th...
- ENG301 Business Communication Assignment No. 02 Due Date...
- CS402 Theory of Automata Assignment 3 solution May 21,2010
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;
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;
}
};
Sponsored Links
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)