Question: C++ Assignment I have the code almost to the point where it will work but am getting class Customer has no member firstNm and lastNm

C++ Assignment I have the code almost to the point where it will work but am getting class "Customer" has no member "firstNm" and "lastNm" for error messages. I'm down to 10 errors where 6 are those, 3 getline is undefined and one ; where I see one. Here is the code I'm working with.

#include

#include

using namespace std;

int index = 0; // variable to hold how many customers are entered

struct Address //Structure for the address.

{

int street;

int city;

int state;

int zipcode;

};

// Customer struct

struct Customer

{

string first Nm, lastNm;

Address busAddr, homeAddr;

};

// Declaration of functions

int displayMenu();

Customer getCustomer();

void showCustomer(Customer);

void allCustomers(Customer[]);

Address getAddress();

void findCust(Customer[], int);

int main()

{

// Declare array of customer struct

Customer cust[100];

// Show menu to user until asks to exit

while (true)

{

// Call displayMenu function and get choice then call function chosen.

int choice = displayMenu();

switch (choice)

{

case 1:

cust[index] = getCustomer();

index++;

break;

case 2:

allCustomers(cust);

break;

case 3:

findCust(cust, index);

break;

case 4:

cout << "Exit program!!" << endl;

return 0;

break;

default:

cout << "Invalid selection!!" << endl;

}

cout << endl;

}

return 0;

}

int displayMenu()

{

// Display menu

cout << "1. Enter new customer" << endl;

cout << "2. Display all customers" << endl;

cout << "3. Display a particular customer" << endl;

cout << "4. Exit the program" << endl;

int choice;

// Ask user to enter a choice

cout << "Enter choice: ";

cin >> choice;

cin.ignore();

cout << endl;

// Return choice

return choice;

}

Address getAddress() {

// Ask user to enter

// street, city , state and zipcode and store in appropriate variables of address

// Return address

Address a;

cout << "Enter street: ";

getline(cin, a.street);

cout << "Enter city: ";

getline(cin, a.city);

cout << "Enter state: ";

getline(cin, a.state);

cout << "Enter zip code: ";

getline(cin, a.zipcode);

return a;

}

Customer getCustomer()

{

// Enter first name, last name and two addresses and return the customer.

Customer c;

cout << "Enter first name: ";

getline(cin, c.firstNm);

cout << "Enter last name: ";

getline(cin, c.lastNm);

cout << "Enter business address - " << endl;

c.busAddr = getAddress();

cout << " Enter home address - " << endl;

c.homeAddr = getAddress();

cout << endl;

return c;

}

void showCustomer(Customer c) {

// Display customer details

cout << "First Name : " << c.firstNm << endl;

cout << "Last Name : " << c.lastNm << endl;

cout << "Business Address : " << c.busAddr.street << " , " << c.busAddr.city << " , " << c.busAddr.state << " , " << c.busAddr.zipcode << endl;

cout << "Home Address : " << c.homeAddr.street << " , " << c.homeAddr.city << " , " << c.homeAddr.state << " , " << c.homeAddr.zipcode << endl;

}

void allCustomers(Customer cust[]) {

for (int i = 0;i

showCustomer(cust[i]);

cout << endl;

}

}

void findCust(Customer cust[], int size) {

// Ask user to enter first and last name

string firstName, lastName;

cout << "Enter first name: ";

getline(cin, firstName);

cout << "Enter last name: ";

getline(cin, lastName);

cout << endl;

for (int i = 0;i

if (cust[i].firstNm == firstName && cust[i].lastNm == lastName) {

showCustomer(cust[i]);

return;

}

}

cout << "Customer not found" << endl;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!