Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CS201 Assignment 4 Solution Last Date 15 July 2010
#1
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
• 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
Quote:#include <iostream.h>
#include <conio.h>
#include <string>
using std:Confusedtring;
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 ();
}
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cs403 Assignment 3 Helping material May 8,2010 viki 1 5,202 04-28-2020, 03:19 PM
Last Post: ClaireBeauc
  cs301 assignment no 3 Solution 20 January 2016 Vuhelper 0 11,088 01-20-2016, 03:32 PM
Last Post: Vuhelper
  CS201 Assignment vo 3 Solution 20th January 2016 Vuhelper 2 2,597 01-20-2016, 03:28 PM
Last Post: Vuhelper
  CS101 Assignment no 3 Solution 20th January 2016 Vuhelper 0 2,279 01-20-2016, 03:25 PM
Last Post: Vuhelper
  SOC101 INTRODUCTION TO SOCIOLOGY assignment no 3 Solution 20 January 2016 Vuhelper 0 1,869 01-20-2016, 03:19 PM
Last Post: Vuhelper
  CS402 Assignment No 4 Solution & Discussion Xpert 0 2,096 08-01-2015, 02:33 AM
Last Post: Xpert
  cs101 Assignment No. 1 Solution 21 may spring 2015 semester Xpert 0 2,908 05-21-2015, 12:41 AM
Last Post: Xpert
  Assignment solution eng 301 due date 20 may 2015 rumesa khan 3 4,530 05-20-2015, 01:34 AM
Last Post: Xpert
  PHY301 Circuit Theory Assignment No. 1 idea Solution spring may 2015 semester Xpert 0 1,558 05-15-2015, 03:52 AM
Last Post: Xpert
  Assignment No. 01 Spring 2015 Information Systems CS507 idea solution spring 2015 Xpert 0 2,446 05-15-2015, 03:49 AM
Last Post: Xpert

Forum Jump:


Users browsing this thread: 1 Guest(s)