Thursday, March 4, 2010

0

Lab oop Answer

  • Thursday, March 4, 2010
  • Ibnu Mahmud Al-Shirazy
  • Have you done this lab, if not here i will provide the answer for you to study it first and do your own source code, not just copy and paste. I help you and you must help me. Below is the source code: Please separate the header file, implementation and main function.

    #ifndef EMPLOYEE_H
    #define EMPLOYEE_H

    #include
    using namespace std;

    class Employee
    {
    private:
    string name;
    int id;
    public:
    Employee(string,int);

    void setName (string);
    string getName ();

    void setId (int);
    int getId ();

    void show_info ();

    };

    #endif

    #include
    #include
    #include "Employee.h"
    using namespace std;

    Employee::Employee(string NM, int ID)
    {
    setName (NM);
    setId (ID);
    }

    void Employee::setName (string NM)
    {
    name = NM;

    }

    string Employee::getName()
    {
    return name;
    }

    void Employee::setId (int ID)
    {
    id = ID;
    }

    int Employee::getId ()
    {
    return id;
    }

    void Employee::show_info ()
    {
    cout << "Name = " << getName() << endl;
    cout << "Id = " << getId () << endl;

    }

    #ifndef CUSTOMER_H
    #define CUSTOMER_H

    #include
    #include "Employee.h"
    using namespace std;

    class Customer : public Employee
    {

    private:
    string custname;
    int custid;

    public:
    Customer (string,int,string,int);

    void setCustname (string);
    string getCustname ();

    void setCustid (int);
    int getCustid ();

    void show_info ();

    };

    #endif

    #include
    #include
    #include "Employee.h"
    #include "Customer.h"
    using namespace std;

    Customer::Customer(string CNM,int CID,string NM,int ID)
    :Employee(NM,ID)
    {
    setCustname (CNM);
    setCustid (ID);
    }

    void Customer::setCustname (string NM)
    {
    custname = NM;
    }

    string Customer::getCustname ()
    {
    return custname;
    }

    void Customer::setCustid (int ID)
    {
    custid = ID;
    }

    int Customer::getCustid ()
    {
    return custid;
    }

    void Customer::show_info ()
    {
    Employee::show_info();
    cout << "Customer Name = " << getCustname() << endl;
    cout << "Customer Id = " << getCustid() << endl;
    cout << "\n\n";
    }


    #ifndef RETAILER_H
    #define RETAILER_H

    #include
    #include "Employee.h"
    using namespace std;

    class Retailer : public Employee
    {
    private:
    string retname;
    int retid;

    public:
    Retailer (string,int,string,int);

    void setRetname (string);
    string getRetname ();

    void setRetid (int);
    int getRetid ();

    void show_info ();

    };

    #endif

    #include
    #include
    #include "Employee.h"
    #include "Retailer.h"
    using namespace std;

    Retailer::Retailer (string RNM,int RID,string NM,int ID)
    :Employee (NM,ID)
    {
    setRetname(RNM);
    setRetid(RID);
    }

    void Retailer::setRetname(string NM)
    {
    retname = NM;
    }

    string Retailer::getRetname()
    {
    return retname;
    }

    void Retailer::setRetid (int ID)
    {
    retid = ID;
    }

    int Retailer::getRetid()
    {
    return retid;
    }

    void Retailer::show_info()
    {
    Employee::show_info();
    cout << "Retailer Name = " << getRetname() << endl;
    cout << "Retailer Id = " << getRetid() << endl;
    cout << "\n\n";
    }


    #include
    #include
    #include "Customer.h"
    #include "Retailer.h"
    using namespace std;

    int main()
    {
    Customer c1("Hilmi Idris",1231,"Shairazey",3455);
    c1.show_info();

    Retailer r1("Mohd Izzat",4455,"Bazli Aghniya",8877);
    r1.show_info();


    return 0;
    }

    Ok. Thats all. If you have any problem or any error occurs. Please contact me immediately, but i am sure no error. Thank you.
    Read more...

    Wednesday, March 3, 2010

    0

    QUIZ 3 OOP ANSWER

  • Wednesday, March 3, 2010
  • Ibnu Mahmud Al-Shirazy
  • #include
    using namespace std;

    class Point
    {

    private:
    int x;
    int y;
    public:
    Point (int = 3, int = 3);
    Point operator + (const Point &);
    Point operator * (const Point &);
    friend ostream& operator << ( ostream &, const Point &);
    friend istream& operator >> ( istream &, Point &);
    };

    Point::Point(int xx , int yy )
    {
    x = xx;
    y = yy;
    }


    Point Point::operator +(const Point & a)
    {
    Point temp;
    temp.x = x + a.x;
    temp.y = y + a.y;
    return temp;
    }

    Point Point::operator *(const Point & b)
    {
    Point temp;
    temp.x = x * b.x;
    temp.y = y * b.y;
    return temp;
    }

    ostream& operator << ( ostream &out, const Point & c)
    {
    out << "(" << c.x << "," << c.y << ")" << endl;
    return out;
    }

    istream& operator >> ( istream &in, Point & d)
    {
    in >> d.x >> d.y;
    return in;
    }

    int main()
    {
    Point p1(2,4), p2, p3, p4, p5, p6;

    cout << "p1 = " << p1;
    cout << "p2 = " << p2;

    p3 = p1 + p2;
    p4 = p1 * p2;

    cout << "\n\np3 = p1 + p2 = " << p3;
    cout << "p4 = p1 * p2 = " << p4;

    cout << "\n\nEnter value of x and y point:" << endl;
    cin >> p5;

    cout << "p5 = " << p5;

    p6 = p5 * p3;
    cout << "\n\np6 = p5 * p3 = " << p6;

    return 0;
    }
    Read more...
    0

    PONTENG KELAS

  • Ibnu Mahmud Al-Shirazy
  • Di akhir-akhir sem ni berlakulah gejala yang tak sihat ini. Ada yang kata "silibus dah habis", "penat sangat la", "mengantuk la", "ada kerja lain".

    Ingatlah kita study kat university ni adalah satu amanah dan tanggungjawab yang perlu dilunaskan.

    "sesungguhnya kami berikan mereka dua jalan, Tapi ramai yang memilih jalan kesenangan".

    Syeikh Idris Al-Marbawi sanggup menyusuri jalan-jalan gajah dalam hutan dari Perak semata-mata hendak berguru dengan Tok Kenali di Kelantan.

    Imam Syafiee R.A. hanya makan sisa-sisa bahagian roti yang keras semasa beliau datang ke Mekah untuk berguru dengan Para Ulama.

    KITA = Proton saga, Motosikal RXZ, Honda Ex5 - Teh 0 ais, Milo ais, Nasi goreng Ladna + Telur Mata, Mee goreng sizzling special, Nasi goreng paprik.

    MALAS = KENAPA ENGKAU WUJUD? BOLEHKAH ENGKAU KELUAR DARI JASADKU INI?
    Read more...

    Subscribe