Please help me

1) Design and implement a class Person. Each object of the class person contains the FirstName and LastName of type character pointer and Age of type int. Besides, the following member functions:

1.Two overloaded constructors - a default constructor with no argument and a constructor that takes two arguments of type character pointer for FirstName and LastName, and integer argument for Age. If the age is less than or equal to 0 or greater than 110, it needs to set the age field value to 1.
2.Method named getFirstName without any parameters, it needs to return the value of the FirstName field.
3.Method named getLastName without any parameters, it needs to return the value of the LastName field.
4.Method named getAge without any parameters, it needs to return the value of the age field.
5.Method named setFirstName with one parameter of type character pointer, it needs to set the value of the FirstName field.
6.Method named setLastName with one parameter of type character pointer, it needs to set the value of the LastName field.
7.Method named setAge with one parameter of type int, it needs to set the value of the age field. If the parameter is less than or equal to 0 or greater than 110, it needs to set the age field value to 1.
8.Method named isTeenager without any parameters, it needs to return true if the value of the age field is greater than 12 and less than 20, otherwise, return false.


2) Write a single C++ statement that declares P1 to be a Person object, and initialize its first name to "Ahmad", last name to "Khalid", and age to 18.


3) Write a single C++ statement that outputs the data stored in the object P1. The output should be like: Ahmad Khalid - age: 18


4) Write C++ statements that determine whether the P1 is a teenager. If it is, print "Is a teenager", otherwise print "Is not a teenager"
Last edited on
Please help for this assignment!
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
It seems fairly straight-forward.

At least you should be able to make an attempt if you've understood anything from reading your book or listening to your tutor.

But just dumping your assignment on a forum and expecting a complete answer you can just hand in without any further effort on your part just isn't going to happen.

We're your guides, not your mules.
@faisal, they're right but here's a small start.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <string>

class Person
{
private:
    std::string FirstName{"No 1st name"};
    int age{0};
    
public:
    Person(){};
    Person(int anAge){ age = anAge;}
    
    std::string getName(){return FirstName;}
    
    bool isTeenAger()
    {
        if( age > 12 && age < 20)
            return true;
        else
            return false;
    }
    
    int getAge(){return age;}
};

int main()
{
    Person p1(10);
    
    std::cout << p1.getName() << " age " << p1.getAge() << " is ";
    if( p1.isTeenAger() )
        std::cout << "a ";
    else
        std::cout << "not a ";
    std::cout << "teenager\n";
    
    return 0;
}


No 1st name age 10 is not a teenager
Program ended with exit code: 0
Yes, I know that, but I could not write this program and I have to submit it today.
@ abuh
It is indeed gratifying to find that you know all that.

Have no fear. I most sincerely didn't want to create the impression that you didn't know 'that' and you have now, more than adequately, allayed my initial concern that you possibly didn't know anything at all.

So, moving forward, the best strategy now is to quickly submit what you do know, including 'that', and avoid trying to find out what everybody else knows, or, even worse, what they don't know which could be voluminous and time-consuming to say the least.

Time is marching on! Submit now!
Registered users can post here. Sign in or register to post.