The post office needs a program that reads in postal address data and then displays the data in a neat format. • Declare four string variables name, addr1, addr2 and postalCode. • First, the main function of the program must input the data by means of a function called inputData. • Second, the main function calls the function displayData to display the name and address as follows: Mr R.S. Bopape P.O. Box 50741 Sandton 2146
#include<iostream>
#include<string>
using namespace std;
void inputData(string *name,string *addr1,string *addr2,string *postalCode){
cout<<"Enter name ";
getline(cin, *name);
cout<<"Enter address 1 ";
getline(cin, *addr1);
cout<<"Enter address 2 ";
getline(cin, *addr2);
cout<<"Enter postal code ";
getline(cin, *postalCode);
}
void displayData(string name,string addr1,string addr2,string postalCode) {
cout<<"POSTAL INFORMATION"<<endl;
cout<<name<<" "<<addr1<<" "<<addr2<<" "<<postalCode<<endl;
}
int main(){
string name, addr1, addr2, postalCode;
inputData(&name, &addr1, &addr2, &postalCode);
displayData(name, addr1, addr2, postalCode);
return 0;}
Comments
Leave a comment