Results 1 to 3 of 3

Thread: C++ Exam Paper Help

  1. #1
    Registered+
    Join Date
    Dec 2008
    Posts
    36
    Thanks
    0
    Thanked
    0 times in 0 posts

    C++ Exam Paper Help

    Hi I'm a n00b at C++ and going through some past exam papers for practice and I finding difficulty with this question can anyone help me please.

    The exam question is:

    c) In this question we will develop a class for a telephone book.

    i) Define a phone_number class containing a name of a person/company (as a
    string) and a phone number (again as a string). Include a constructor and
    appropriate selector methods.

    My answer is:

    #include <iostream>
    #include <string>
    using namespace std;

    class Phone_number
    {
    public:
    string name; //name of person/company
    string phoneNumber; //phone number as string

    Phone_number(string name_, string phoneNumber_) : name(name_), phoneNumber(phoneNumber_){};
    //initializes the name and phone to argurments

    Phone_number(Phone_number &p); // copy constructor.

    /*This is a selector method to get the name.*/
    string Phone_number::getName()
    {
    return name;
    }

    /*This is a selector method to get the phoneNumber.*/
    string Phone_number::getNumber()
    {
    return phoneNumber;
    }
    };

    I took selector method to mean accessor method was I right in doing so?

    P.S. The question that follows on this one is confusing, can someone help me with understanding it, here it is.

    ii) Write an appropriate overloading of the operator== for this class.

  2. #2
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable

    Re: C++ Exam Paper Help

    They'd be looking for something like this:
    Code:
            bool Phone_number::operator== (Phone_number &p) {
                    if(name == p.name && phoneNumber == p.phoneNumber) {
                            return true;
                    } else {
                            return false;
                    }
            }
    Programming questions should go in the software development sub-forum btw.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  3. #3
    Registered User
    Join Date
    Jun 2011
    Location
    Canada
    Posts
    1
    Thanks
    0
    Thanked
    0 times in 0 posts

    My Introduction

    Thanks for the oportunity to hang out on here and learn some stuff I never heard of forums.hexus.net before.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. The Miracle of Toilet Paper
    By dave87 in forum General Discussion
    Replies: 3
    Last Post: 31-01-2007, 09:09 PM
  2. My A2 Level exam!! (So far anyway) Take a peek
    By unreal in forum Consumer Electronics
    Replies: 23
    Last Post: 19-05-2006, 08:04 PM
  3. OpenOffice Paper sizes
    By Raz316 in forum Software
    Replies: 4
    Last Post: 11-08-2005, 10:27 AM
  4. Bendy electronic paper from Fujitsu
    By Steve in forum HEXUS News
    Replies: 2
    Last Post: 15-07-2005, 02:59 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
  •