Sponsored Links


Results 1 to 2 of 2

Thread: CS201 Assignment 4 Solution Last Date 15 July 2010

  1. #1
    Senior Member Guru's Avatar
    Join Date
    May 2010
    Location
    Jhelum
    Posts
    117

    CS201 Assignment 4 Solution Last Date 15 July 2010

    Sponsored Links


    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

    Sponsored Links


    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 ();
    }

  2. #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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 15
    Last Post: 01-11-2012, 05:19 PM
  2. Replies: 7
    Last Post: 07-31-2010, 08:29 AM
  3. CS201 Assignment 4 Solution, June 2010
    By viki in forum Assignments & Solutions
    Replies: 5
    Last Post: 07-02-2010, 12:26 AM
  4. Replies: 0
    Last Post: 05-16-2010, 05:26 AM
  5. CS201 Solution 2nd Assignment Spring 2010 May 4
    By viki in forum Assignments & Solutions
    Replies: 0
    Last Post: 05-04-2010, 10:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft