Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify your contact manager program to separate all implementation of your classes from the header files. You should have a .cpp file and a .h

Modify your contact manager program to separate all implementation of your classes from the header files. You should have a .cpp file and a .h file for each class you create.

 

Currently, the program is in one main.cpp file. The professor now wants .cpp and .h files for each class. What would the modified program look like?

//main.cpp
#include
#include
#include
#include

using namespace std;

// Variables for username and password to the program
string usernameCorrect = "UserConnect";
string passwordCorrect = "Password123";
string usernameInput = "";
string passwordInput = "";

// Variables for arrays
string firstnameArray[50];
string lastnameArray[50];
string numberArray[50];
string zipcodeArray[50];
string ssnArray[50];

// Variable for array size
int arraySize = 0;

// Variables for sorting and searching database
string tempFirstName = "";
string tempLastName = "";
string tempNumber = "";
string tempZipCode = "";
string tempSSN = "";
string soughtValue = "";
int index = -1;
int pass = -1;

void getUserPassword() {
// Get username and password from the user
cout << "Please enter username: ";
cin >> usernameInput;

cout << "Please enter password: ";
cin >> passwordInput;
}

void userAdd() {
// Get how many contacts user wants to add
cout << "Please enter the number of contacts you want to add: ";
cin >> arraySize;

// Get contact info from user
cout << "Please enter contacts first name, last name, phone number, "
<< "zip code, and last 4 digits of their SSN." << endl;

for (int i = 1; i < arraySize + 1; i++) {
cout << "Please enter conact's first name " << i << ": ";
cin >> firstnameArray[i];

cout << "Please enter contact's last name " << i << ": ";
cin >> lastnameArray[i];

cout << "Please enter contact's phone number " << i << ": ";
cin >> numberArray[i];

cout << "Please enter contact's zip code " << i << ": ";
cin >> zipcodeArray[i];

cout << "Please enter the last 4 digits of contact's " << i << " SSN: ";
cin >> ssnArray[i];
}
}

void ascendingOrder() {
// Sort array in ascending order based on first name
for (pass = 0; pass < arraySize; pass++) {
for (index = 0; index < arraySize - pass; index++) {
if (firstnameArray[index] > firstnameArray[index + 1]) {
tempFirstName = firstnameArray[index];
firstnameArray[index] = firstnameArray[index + 1];
firstnameArray[index + 1] = tempFirstName;

tempLastName = lastnameArray[index];
lastnameArray[index] = lastnameArray[index + 1];
lastnameArray[index + 1] = tempLastName;

tempNumber = numberArray[index];
numberArray[index] = numberArray[index + 1];
numberArray[index + 1] = tempNumber;

tempZipCode = zipcodeArray[index];
zipcodeArray[index] = zipcodeArray[index + 1];
zipcodeArray[index + 1] = tempZipCode;

tempSSN = ssnArray[index];
ssnArray[index] = ssnArray[index + 1];
ssnArray[index + 1] = tempSSN;
}
}
}
}

void printContent() {
// Display content of the array
for (int j = 1; j < arraySize + 1; j++) {
cout << setw(5) << j + 1 << ". " << "First & Last Name: " << setw(5)
<< firstnameArray[j] << " " << lastnameArray[j] << " | "
<< "Number: " << zipcodeArray[j] << " | " << "SSN: "
<< ssnArray[j] << endl;
}
}

void searchArray() {
// Get the search term
cout << "Please enter a first name to search for and press enter.";
cin >> soughtValue;

// Search the array
for (index = 0; index < arraySize; index++) {
if (firstnameArray[index] == soughtValue) {
break;
}
}
if (index > arraySize) {
cout << "The name " << soughtValue << " was not found." << endl;
} else {
cout << soughtValue << " has the info: " << "First & Last Name: "
<< setw(2) << firstnameArray[index] << " "
<< lastnameArray[index] << " | " << "Number: " << setw(2)
<< numberArray[index] << " | " << "Zip Code: " << setw(2)
<< zipcodeArray[index] << " | " << "SSN: " << ssnArray[index]
<< endl;
}
}

int main() {
// Call the username and password function
getUserPassword();

while (usernameInput == usernameCorrect && passwordInput == passwordCorrect) {
int choice;

while (1) {
cout << "Press 1 to add user(s): " << endl;
cout << "Press 2 to sort data in ascending order: " << endl;
cout << "press 3 to print data: " << endl;
cout << "Press 4 to search for a user by first name: " << endl;
cout << "Press 5 to end the program: " << endl;

cin >> choice;
switch (choice) {
case 1:
cin.ignore();
userAdd();
break;
case 2:
ascendingOrder();
break;
case 3:
printContent();
break;
case 4:
searchArray();
break;
case 5:
return 0;
break;
default:
;

}

}
}
if (usernameInput != usernameCorrect && passwordInput != passwordCorrect) {
cout << "Username and/or Password not found, please try again." << endl;
return 0;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To modify the contact manager program to separate the implementation of classes from the header files you would typically create header h and implementation cpp files for each class Lets start by iden... 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

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

More Books

Students also viewed these Algorithms questions

Question

Find each product. -3a+(4 + a)

Answered: 1 week ago

Question

Distinguish between volume-based and non-volume-based cost drivers.

Answered: 1 week ago

Question

Describe how self-defeating attitudes create a vicious cycle.

Answered: 1 week ago

Question

What are the modules of C++ programs called?

Answered: 1 week ago