Write a two-class C++ application that creates a customer code to be placed on a
ID: 3744705 • Letter: W
Question
Write a two-class C++ application that creates a customer code to be placed on a mailing label for a magazine. Allow the user to input their full name with the first name entered first. Prompt them to separate their first and last name with a space. Ask for their birthdate in the format of mm/dd/yyyy. Ask for the month (number) they purchased a subscription and ask for their zip code. Your mailing label should contain the last name, followed by their year of birth, the number of characters in the full name, the first three characters of the month they purchased the subscription, and the last two digits of their zip. The code for Bob Clocksom born 01/22/1993, who purchased his subscription during the 10th month of the year and lists 32226 as his zip code would be Clocksom9312Oct26. It needs to be a two-class application in C++ please and thank you!
Explanation / Answer
Code:
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iterator>
using namespace std;
class Person{
private:
string firstName,lastName,birthDay,zipcode;
int months;
string mon[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
public:
Person(string fName,string lName, string bDate, string zCode,int m){
firstName = fName;
lastName = lName;
birthDay = bDate;
zipcode = zCode;
months = m;
}
string getCode(){
string ans = lastName;
std::stringstream ss(birthDay);
std::string token;
std::getline(ss, token, '/');
std::getline(ss, token, '/');
ans = ans + token.substr(token.size() - 2);
int len = firstName.size() + lastName.size() +1;
ans = ans + std::to_string(len);
ans = ans + mon[months-1];
ans = ans + zipcode.substr(zipcode.size()-2);
return ans;
}
};
class CustomerCodeGenerator{
public:
string genarateCode(){
string firstName,lastName,birthDay,zipcode;
int months;
cout<<"Enter firstName lastname space separated: ";
cin>>firstName>>lastName;
cout<<"Enter date of birth in dd/mm/yyyy format: ";
cin>>birthDay;
cout<<"Enter zipcode: ";
cin>>zipcode;
cout<<"Enter month of subscription: ";
cin>>months;
Person p(firstName,lastName,birthDay,zipcode,months);
cout<< " Generated code: "<<p.getCode();
}
};
int main()
{
CustomerCodeGenerator customerCodeGenerator;
customerCodeGenerator.genarateCode();
return 0;
}
Sample Output:
Enter firstName lastname space separated: Bob Clocksom
Enter date of birth in dd/mm/yyyy format: 01/22/1993
Enter zipcode: 32226
Enter month of subscription: 10
Generated code: Clocksom2212Oct26
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.