"Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. The output should be a list of email addresses where the address is of the following form: first.last@mycollege.edu"

Respuesta :

Answer:

#include<iostream>

using namespace std;

int main()

{

   string f[50],l[50],str1,str;   //f[] will store firstnames and l[] lastnames

   int i;

   cout<<"Enter firstnames and enter # to stop\n";

   cin>>str;

   for(i=0;str!="#";i++)       //# will be the sentinel character

   {

       f[i]=str;

       cin>>str;

   }

   cout<<"Enter lastnames and enter # to stop\n";

   cin>>str1;

   for(i=0;str1!="#";i++)

   {

       l[i]=str1;

       cin>>str1;

   }

   int n=i;        //n wiill be number of elements in array

   cout<<"\nList of emails are : \n";

   for(i=0;i<n;i++)        //loop to print list of emails

   {

       cout<<f[i]<<"."<<l[i]<<"@mycollege.edu"<<endl;

   }

   return 0;

}

OUTPUT :

Please find the attachment below.

Explanation:

Two arrays are maintains which are f[] and l[]. f[] stores firstnames and l[] stores lastnames. First 2 loops are reading firstnames and lastnames which will break if '#' is typed as it is considered as a sentinel character here which is assured by checking the condition in the loop. Then n variable is used to store the length of the arrays. Both arrays have to be of equal length as email ids contains both firstname and lastname. Then a loop is created to print email ids of the format specified by using arrays f[] and l[].

Ver imagen flightbath