Question

In: Computer Science

Language: c++ works in visual basic Write a program that uses an array of nested structs...

Language: c++

works in visual basic

Write a program that uses an array of nested structs to store the addresses for your store’s customers.  Each customer has a name and two addresses: home address and business address.  Each address has a street, city, state, and zip code. Requirements: 1. Data structure a. Define an Address struct with street, city, state and zip fields b. Define a Customer struct with lastNm and firstNm fields, plus homeAddr and busAddr fields of type Address c. Declare an array of type Customer 2. Use a menu‐driven program with the following selections: a. Enter new customer b. Display all customers c. Display a particular customer d. Exit the program 3. Define the following 5 functions a. int displayMenu(); Outputs the menu selections Inputs the users selection Validates that the user has entered a valid selection b. Customer getCustomer(); Asks the user to input the customer’s first name, last name and the two addresses and stores in a single Customer struct c. void showCustomer(Customer); Outputs the information for a single Customer struct d. Address getAddress(); Asks the user to enter each component of the address (street, city, state and zip) and stores it in a single address struct. Note that street will contain embedded blanks, so you will need to use getline. Since you are mixing cin and getline, you will need to use cin.ignore to skip over the last endline character in the input prior to using getline. e. void findCust(Customer[], int); Asks the user to enter a customer’s first and last names Searches the array of Customers for a match If there is a match, prints out all information for the particular customer If not match, prints an error message.

Solutions

Expert Solution

#include<bits/stdc++.h>
using namespace std;

#define Size 100000

// Defined Structure Address
struct Address {
    string street, city, state, zipcode;
};

// Defined Structure Customer
struct Customer {
    string firstNm, lastNm;
    Address homeAddr, busAddr;
};


// Function to display menu
int displayMenu() {
    int choice;
    cout<<endl;
    cout<<"--------------MENU--------------"<<endl;
    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;
    cout<<endl<<"Enter your choice : ";

    cin>>choice;
    return choice;
}

// Function to get address input from user
Address getAddress() {
    string street, city, state, zipcode;
    Address addr;
    cout<<"---- Enter Address ----"<<endl;

    cout<<"Enter street : ";
    getline(cin,street);
    addr.street = street;

    cout<<"Enter City : ";
    cin>>city;
    addr.city = city;

    cout<<"Enter State : ";
    cin>>state;
    addr.state = state;

    cout<<"Enter Zipcode : ";
    cin>>zipcode;
    addr.zipcode = zipcode;

    return addr;
}

// Function to get customer details input from user
Customer getCustomer() {
    Address homeAddr, busAddr;
    string firstNm, lastNm;
    Customer cus;

    cout<<"------ Enter New Customer ------"<<endl;

    cout<<"Enter First Name : ";
    cin>>firstNm;
    cus.firstNm = firstNm;

    cout<<"Enter Last Name : ";
    cin>>lastNm;
    cus.lastNm = lastNm;

    cout<<"Enter Details for Home Address"<<endl;
    homeAddr = getAddress();
    cus.homeAddr = homeAddr;

    cout<<"Enter Details for Business Address"<<endl;
    busAddr = getAddress();
    cus.busAddr = busAddr;

    return cus;
}

// Function to show Address
void showAddress(Address addr) {
    cout<<"Street  : "<<addr.street<<endl;
    cout<<"City    : "<<addr.city<<endl;
    cout<<"State   : "<<addr.state<<endl;
    cout<<"Zipcode : "<<addr.zipcode<<endl;
}

// Function to show Customer
void showCustomer(Customer cus) {
    cout<<"First Name : "<<cus.firstNm<<endl;
    cout<<"Last Name  : "<<cus.lastNm<<endl;
    cout<<"Home Address Details"<<endl;
    showAddress(cus.homeAddr);
    cout<<"Business Address Details"<<endl;
    showAddress(cus.busAddr);
    cout<<"--------------------------------------"<<endl;
}

// Function to find a particular customer
void findCust(Customer cus[], int n) {
    string firstNm, lastNm;
    cout<<"---- FINDING CUSTOMER ----"<<endl;
    cout<<"First Name : ";
    cin>>firstNm;
    cout<<"Last Name  :";
    cin>>lastNm;

    int flag = 0;

    for(int i = 0 ; i < n ; i++) {
        if(cus[i].firstNm == firstNm && cus[i].lastNm == lastNm) {
            flag++;
            cout<<"Customer Found ..!!"<<endl;
            showCustomer(cus[i]);
            break;
        }
    }

    if(flag == 0) cout<<"Error .. !! Customer Not Found."<<endl;
}

int main() {

    int choice, n = 0;
    Customer cus[Size];

    while(1) {

        choice = displayMenu();

        if(choice == 1) {

            Customer newCus = getCustomer();
            cus[n++] = newCus;

        } else if(choice == 2) {

            for(int i = 0 ; i < n ; i++) {
                cout<<"Customer No. "<<i<<endl;
                showCustomer(cus[i]);
            }

        } else if(choice == 3) {

            findCust(cus,n);

        } else {
            break;
        }

    }


        return 0;
}

Related Solutions

Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 2, … Fib(n) = Fib(n-1) + Fib(n-2). Place each value in the EAX register and display it with a call DumpRegs statement inside the loop For example: Fib(1) = 1, Fib(2) = 2, Fib(3) = Fib(1) + Fib(2) = 3, Fib(4) = Fib(2) + Fib(3)...
IN C++ Write a program that uses nested loops to collect data and calculate the average...
IN C++ Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the ­­program should display the...
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
Write a C++ program that uses nested loops to collect data and calculate the average rainfall...
Write a C++ program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number...
Use Visual Basic Language In this assignment you will need to create a program that will...
Use Visual Basic Language In this assignment you will need to create a program that will have both a “for statement” and an “if statement”. Your program will read 2 numbers from the input screen and it will determine which is the larger of the 2 numbers. It will do this 10 times. It will also keep track of both the largest and smallest numbers throughout the entire 10 times through the loop. An example of the program would be...
Write a C Program that uses file handling operations of C language. The Program should perform...
Write a C Program that uses file handling operations of C language. The Program should perform following operations: 1. The program should accept student names and students’ assignment marks from the user. 2. Values accepted from the user should get saved in a .csv file (.csv files are “comma separated value” files, that can be opened with spreadsheet applications like MS-Excel and also with a normal text editor like Notepad). You should be able to open and view this file...
In C++, write a program that uses array to calculate the factorial of a reasonable large...
In C++, write a program that uses array to calculate the factorial of a reasonable large number (say, up to 2,000).
In C++. Write a program that uses array to calculate the factorial of a reasonable large...
In C++. Write a program that uses array to calculate the factorial of a reasonable large number (say, up to 2,000).  
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT