Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Given code #include #include #include using namespace std; class ContactType { public: ContactType(string, string, int, string, string); ContactType(); string getFirstName() const; string getLastName() const;

image text in transcribed
C++
Given code
#include
#include
#include
using namespace std;
class ContactType
{
public:
ContactType(string, string, int, string, string);
ContactType();
string getFirstName() const;
string getLastName() const;
int getAge() const;
string getEmail() const;
string getPhone() const;
void setFirstName(string);
void setLastName(string);
void setAge(int);
void setEmail(string);
void setPhone(string);
void printData() const;
private:
string firstName;
string lastName;
int age;
string email;
string phone;
};
ContactType::ContactType(string fName, string lName, int ag, string em, string ph)
:firstName(fName), lastName(lName), age(ag), email(em), phone(ph) {}
ContactType::ContactType()
: firstName("unknown"), lastName("unknown"), age(0), email("unknown"), phone("unknown") {}
string ContactType::getFirstName() const
{
return firstName;
}
string ContactType::getLastName() const
{
return lastName;
}
int ContactType::getAge() const
{
return age;
}
string ContactType::getEmail() const
{
return email;
}
string ContactType::getPhone() const
{
return phone;
}
void ContactType::setFirstName(string fName)
{
firstName = fName;
}
void ContactType::setLastName(string lName)
{
lastName = lName;
}
void ContactType::setAge(int ag)
{
age = ag;
}
void ContactType::setEmail(string em)
{
email = em;
}
void ContactType::setPhone(string ph)
{
phone = ph;
}
void ContactType::printData() const
{
cout
}
/// TODO: The array will no longer be the predetermined
/// length 10. Please comment out or delete this constant.
const int ARR_LENGTH = 10;
int main()
{
/// TODO: Create an integer variable called length and ask
/// the user to input the number of contacts to be stored.
/// Store that user input in length.
///
/// TODO: Replace this statement with a statement that uses
/// a ContactType pointer to point to a newly allocated array
/// of the exact length specified by the user.
///
ContactType contactBook[ARR_LENGTH];
/// TODO: Rewrite the for-loops' condition since the named
/// constant ARR_LENGTH no longer exists in our program.
///
for (int i = 0; i
{
contactBook[i].setFirstName("First_" + to_string(i));
contactBook[i].setLastName("Last_" + to_string(i));
contactBook[i].setAge(i);
contactBook[i].setEmail("Email_" + to_string(i));
contactBook[i].setPhone("Phone_" + to_string(i));
}
/// TODO: Rewrite the for-loops' condition since the named
/// constant ARR_LENGTH no longer exists in our program.
///
for (int i = 0; i
{
contactBook[i].printData();
}
cout
/// TODO: Create a pointer of the type ContactType called
/// topContact. We will use this pointer to keep track of
/// our most frequent contact.
///
/// TODO: Lets decide our most frequent contact is fifth in the
/// array (the one located at array subscript [4]). Point
/// topContact to that fifth contact in the array.
///
/// TODO: Use the topContact pointer to call that fifth
/// contacts print function. We can use a pointer to access a
/// class member using -> (the member access arrow).
///
/// TODO: Before were done, remember to delete or release that
/// dynamically allocated memory.
///
/// TODO: And now that that memory has been released, nullify
/// your pointers.
///
return 0;
}
Question: The file Labll vl.cpp provided on Canvas creates an array of ten ContactType objects. But a user might prefer to store more than or fewer than ten contacts in a contact book. Our task is to amend the program to let the user choose how many contacts to store. We will then dynamically allocate the appropriate amount of memory and populate the array with the number of contacts the user specified. To accomplish this, please make these following changes 1) 2) Inside main), create an integer variable called length, and prompt the user to enter a 3) Comment out or delete the statement: ContactType-contactBookARR LENGTH] Replace it The array will no longer be the predetermined length 10. Please comment out or delete the statement: const int ARR LENGTH 0 desired number of contacts. Store that user input in length with a statement that uses a ContactType pointer to point to a newly allocated array of the exact length specified by the user 4) Rewrite the for-loops, condition: for (int - 6;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory Icdt 97 6th International Conference Delphi Greece January 8 10 1997 Proceedings Lncs 1186

Authors: Foto N. Afrati ,Phokion G. Kolaitis

1st Edition

3540622225, 978-3540622222

More Books

Students also viewed these Databases questions

Question

List the variable overhead variances and briefly describe each.

Answered: 1 week ago

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago