Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   C++ (https://www.askmehelpdesk.com/forumdisplay.php?f=439)
-   -   How to write the code? (https://www.askmehelpdesk.com/showthread.php?t=737771)

  • Mar 6, 2013, 08:39 AM
    babychick2
    how to write the code?
    can somebody solve this question if was using c++ studio..

    Create an advance data type to represent a Complex Number. A complex number is something which has two parts,
    the real part and an imaginary part. Some example complex numbers are:
    2+3i, -5+7i, -1-2i, and so on. Name this class "Complex". This class should have only two member variables:
    1) real (int type)
    2) imaginary (int type)

    Make all the member variables private. For this class, implement the following:

    1) Constructors (default and overloaded), Getters and Setters.
    2) overload the following operators as friend functions: ==, +, binary -, unary -, <<, >>
    3) Friend function named Multiply which can multiply two complex numbers and return the result complex number
    4) Member function named Multiply which can multiply two complex numbers and return the result complex number
    5) Non-friend Non-member function named NonMemberMultiply which can multiply two complex numbers and return the result
    complex number.

    Note the following points:
    1) the overloaded operator "<<" should print the complex number in the form like this: 2+3i, or -2+4i
    2) also note that, if a complex number has real part 0, then it should be printed like this: 4i. Similarly if it has imaginary part 0, it should be printed just like an integer like this: -2.
    3) Your code must be Efficient (call-by-reference) and Secure (const) as much as possible.
    4) note that multiplying two complex numbers, for example 2-3i and -4+5i works like this:
    (2-3i) * (-4+5i) = 2*(-4+5i) -3i*(-4+5i)
    = -8+10i + 12i -15(I*i)
    = -8+10i + 12i -15(-1)
    = -8+10i + 12i +15
    = 7+22i
  • Apr 15, 2013, 09:41 AM
    babychick2
    ?? //
    Create a class to represent student. This class should contain the following public members:

    1) ID: int
    2) FirstName: string
    3) College: string
    4) Major: string
    5) GPA: double
    6) Friends: Student *
    7) next: Student *

    Implement the following for this class:

    1) Default and Overloaded constructors.
    2) Write a function "void CreateList(Node * & h)" which will create a linked list of couple of students (say 5 students) and for each student this function will add a number of friends as another linked list.
    3) Write a Print function to print the entire linked list as mentioned in the project file.
    4) Write a function "bool FindFriendship(3, 6)" which will return true if student with id=6 is a friend of student with id=3. Otherwise it will return false.
    5) Write main() where you will call CreateList(), Print() and FindFriendship() functions to check their working.
  • Apr 15, 2013, 09:43 AM
    JudyKayTee
    It's against AMHD policy to do homework.

    - this is a particularly lengthy and complicated problem, which you have copied.

    I'm sure your textbook has the answers.
  • Apr 15, 2013, 10:01 AM
    babychick2
    help me answer this
    Create a class to represent student. This class should contain the following public members:

    1) ID: int
    2) FirstName: string
    3) College: string
    4) Major: string
    5) GPA: double
    6) Friends: Student *
    7) next: Student *

    Implement the following for this class:

    1) Default and Overloaded constructors.
    2) Write a function "void CreateList(Node * & h)" which will create a linked list of couple of students (say 5 students) and for each student this function will add a number of friends as another linked list.
    3) Write a Print function to print the entire linked list as mentioned in the project file.
    4) Write a function "bool FindFriendship(3, 6)" which will return true if student with id=6 is a friend of student with id=3. Otherwise it will return false.
    5) Write main() where you will call CreateList(), Print() and FindFriendship() functions to check their working.
  • Apr 15, 2013, 10:10 AM
    Curlyben
    What do YOU think ?
    While we're happy to HELP we won't do all the work for you.
    Show us what you have done and where you are having problems..
  • Apr 15, 2013, 12:18 PM
    babychick2
    this is what I did and it is showing errors. Please correct the mistakes
    #include <iostream>
    #include <string>
    using namespace std;

    class Student
    {
    public:
    int ID;
    string FirstName;
    string College;
    string Major;
    double GPA;
    Student*Friends;
    Student*next;
    Student();
    Student(int id1, string FirstName1, string College1, string Major1, double GPA1);
    CreateList(Node*& head, int n)

    bool FindFriendship(int a, int b);
    };

    Student::Student()
    {
    int ID=0;
    string FirstName=" ';
    string College=' ';
    string Major=' ';
    double GPA=0;
    friends=NULL;
    next=NULL;

    }

    Student::Student(int id1, string FirstName1, string College1, string Major1, double GPA1)
    {
    int id=id1;
    string FirstName='FirstName1';
    string College='College1';
    string Major='Major1';
    double GPA=GPA1;
    }

    void Student::CreateList(Student *&h, int n)
    {
    void Create(Node*& head, int n)
    {
    AddHead(h, "Sara", 1, "College of computer engineering and science", "Information Technology", 3.25);
    AddHead(h, "Hiba", 2, "College of Engineering", "Interior Design", 2.7);
    AddHead(h, "Lujain", 3, "College of Business Administration", "MIS", 3.01);
    AddHead(h, "Amna", 4, "College of Arts and Sciences", "Law", 3.68);
    AddHead(h, "Nasreen", 5, "College of computer engineering and science", "Computer Science", 3.44);

    Student*a=new Student("Sara", 1, "College of computer engineering and science", "Information Technology", 3.25);
    Addtail(a, "Nasreen", 5, "College of computer engineering and science", "Computer Science", 3.44);
    Addtail(a, "Lujain", 3, "College of Business Administration", "MIS", 3.01);
    Addtail(a, "Amna", 4, "College of Arts and Sciences", "Law", 3.68);

    Student*b=new Student("Hiba", 2, "College of Engineering", "Interior Design", 2.7);
    Addtail(b, "Nasreen", 5, "College of computer engineering and science", "Computer Science", 3.44);

    Student*c=new Student("Lujain", 3, "College of Business Administration", "MIS", 3.01);
    Addtail (c, "Sara", 1, "College of computer engineering and science", "Information Technology", 3.25);
    Addtail (c, "Amna", 4, "College of Arts and Sciences", "Law", 3.68);

    Student*d=new Student("Amna", 4, "College of Arts and Sciences", "Law", 3.68);
    Addtail (d,"Hiba", 2, "College of Engineering", "Interior Design", 2.7);

    Student*e=new Student("Nasreen", 5, "College of computer engineering and science", "Computer Science", 3.44);
    Addtail (e, "Lujain", 3, "College of Business Administration", "MIS", 3.01);

    }

    void Print(student* h)
    {
    while(h)
    {
    cout<<h->id;
    cout<<h->firstname
    cout<<h->college;
    cout<<h->GPA;
    cout<<h->major;
    h=h->next;
    }
    cout<<endl;

    int main()
    {
    student*head=NULL;
    head->next=(
    print (head);
    createlist(head,5);
    return 0;
    }
    Quote:

    Originally Posted by Curlyben View Post
    What do YOU think ?
    While we're happy to HELP we wont do all the work for you.
    Show us what you have done and where you are having problems..

  • Apr 15, 2013, 12:21 PM
    ScottGem
    What errors and where?

  • All times are GMT -7. The time now is 08:03 AM.