Trusted by millions of Kenyans
Study resources on Kenyaplex

Get ready-made curriculum aligned revision materials

Exam papers, notes, holiday assignments and topical questions – all aligned to the Kenyan curriculum.

a)Create a class that contains a person's name and telephone number. Using new, dynamically allocate an object of this class and put your name and...

a)Create a class that contains a person's name and telephone number. Using new, dynamically allocate an object of this class and put your name and phone number into these fields within this object.
b).What are the two ways that new might indicate an allocatn failure?

Answers


Davis
a).#include
#include
using namespace std;
class phone {
char name[40];
char nur[14];
public:
void store(char *n, char *num);
void show();
};
void phone::store(char *n, char *num) {
strcpy(name, n);
strcpy(number, num);
id phone::show()
{
cout <cout << "\n";
}
int main()
{
phone *p;
p = new phone;
if(!p) {
cout << "Allocation error.";
n 1;
}
p->store("Isaac Newton", "111 555-2323");
p->show();
delete p;
return 0;
}


b).On failure, new will either return a null pointer or generate an exception.You must check you compiler's documentation to determine which approach is used. In standard C++, new generates an exception by default
Githiari answered the question on May 31, 2018 at 17:12

Answer Attachments

Exams With Marking Schemes

Related Questions