# Thread: CS201 Assignment 4 Solution Last Date 15 July 2010

1. ## CS201 Assignment 4 Solution Last Date 15 July 2010

CS201 Introduction to Programming
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

 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;
}
};

int main()
{
Student y;
Student z
("Orail",123456789,"Spring 2010",3.97);
y.print();
z.print();
system("pause");
return 0;
getch ();
}

3. 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