Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 1 Lnai 6321

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215879X, 978-3642158797

More Books

Students also viewed these Databases questions

Question

=+4. What information remains to be obtained?

Answered: 1 week ago

Question

What must a creditor do to become a secured party?

Answered: 1 week ago