Create two classes. The first holds customer data—specifically, a customer number and zip code. The second, a class for cities, holds the city name, state, and zip code. Additionally, each class contains a constructor that takes parameters to set the field values. Create a friend function that displays a customer number and the customer’s city, state, and zip code.Write a brief main() function to prompt the user to input customer and city information, create objects of the respective classes based on user input, and then call the friend function to display the customer information along with the associated city, state, and zip code. While calling Friend function output the statement “Calling friend function”Ensure the user provides the following details:Customer numberCity nameStateZip code
Question
Create two classes. The first holds customer data—specifically, a customer number and zip code. The second, a class for cities, holds the city name, state, and zip code. Additionally, each class contains a constructor that takes parameters to set the field values. Create a friend function that displays a customer number and the customer’s city, state, and zip code.Write a brief main() function to prompt the user to input customer and city information, create objects of the respective classes based on user input, and then call the friend function to display the customer information along with the associated city, state, and zip code. While calling Friend function output the statement “Calling friend function”Ensure the user provides the following details:Customer numberCity nameStateZip code
Solution
Sure, here is the C++ code that fulfills your requirements:
#include <iostream>
#include <string>
using namespace std;
class City; // Forward declaration
class Customer {
private:
int customerNumber;
string zipCode;
public:
Customer(int c, string z): customerNumber(c), zipCode(z) {}
friend void display(Customer &c, City &ci);
};
class City {
private:
string cityName;
string state;
string zipCode;
public:
City(string cn, string s, string z): cityName(cn), state(s), zipCode(z) {}
friend void display(Customer &c, City &ci);
};
void display(Customer &c, City &ci) {
cout << "Calling friend function" << endl;
cout << "Customer number: " << c.customerNumber << endl;
cout << "City: " << ci.cityName << ", State: " << ci.state << ", Zip code: " << ci.zipCode << endl;
}
int main() {
int customerNumber;
string cityName, state, zipCode;
cout << "Enter customer number: ";
cin >> customerNumber;
cin.ignore();
cout << "Enter city name: ";
getline(cin, cityName);
cout << "Enter state: ";
getline(cin, state);
cout << "Enter zip code: ";
getline(cin, zipCode);
Customer customer(customerNumber, zipCode);
City city(cityName, state, zipCode);
display(customer, city);
return 0;
}
This code first declares two classes, Customer and City, with the necessary fields and constructors. It also declares a friend function display() that can access the private members of both classes. In the main() function, it prompts the user for the necessary information, creates objects of the Customer and City classes based on this information, and then calls the display() function to print out the customer information along with the associated city, state, and zip code.
Similar Questions
Define a class named Customer that holds private fields for a customer ID number, last name, first name, and credit limit. Include four public functions that each set one of the four fields. Do not allow any credit limit over $10,000. Include a public function that displays a Customer’s data.a. Write a main()function in which you declare a Customer, set the Customer’s fields, and display the results.b. Write a main()function that declares an array of five Customer objects. Prompt the user for values for each Customer, and display all five Customer objects
Write a statement that will select the City column from the Customers table.
Write a class that represents a person’s mailing address. It should have separate fields forthe name, street address, city, state and ZIP code. Write an application AddressBook, toincorporate address book application :-(a) To add addresses.(b) Print addresses.
write a function that accepts 10 users name and phone number and structure your data in such a way that when i input a users name it returns the phone number and if the name doesn't exist it should return 00000
Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone_number, and e-mail address. A student has a status (freshman, sophomore, junior, or senior). An employee has an office, salary. A faculty member has office_hours and a rank. A staff member has a title. Override the toString() method in each of these classes to display their details. Write a Java application and subsequent pseudocode to implement/simulate the same.Input :First line must read the Type of the Object(Person(P)/Employee(E)/Faculty(F)/Student(S)/Staff(T).Second line onwards read details such as name, address, phoneNo, Email and soonOutput :Print ClassName : Name, Address, PhonNo, Email, and rest of the datamembers of that class. For Example :if Type = P, then print Person : Name, Address, PhoneNo, Emailif Type = S, then print Student : Name, Address, PhoneNo, Email, Statusif Type = E, then print Employee : Name, Address, PhoneNo, Email, Office, Salaryif Type = T, then print Staff : Name, Address, PhoneNo, Email, Office, Salary, Titleif Type = F, then print Faculty : Name, Address, PhoneNo, Email, Office, Salary, Office_Hrs, RankNote :The Status for Student is freshman, sophomore, junior, or senior.Overide only toString() method in all the Classes.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.