In: Computer Science
3. [1 pts] Part A. Write a program for the GW Admissions Office. a) Request the staff to enter a string, to indicate someone’s NetID. b) Generates an email address, by appending “@gwmail.gwu.edu” to the user input c) Print the generated email account [2 pts]
Part B. Write a program to meet additional requirements. In addition to requirements in Part A, your function should perform the following check: a) If the user input is longer than 10 characters (11 or more), truncate it and use the first 10 characters to generate an email address. Print the email address.
Program in c++ Part A:
#include <iostream>
#include<string.h>
using namespace std;
int main()
{
string s="@gwmail.gwu.edu"; // given in program
string str;
string email1;
cout<<"Please Enter a String"<<endl;
getline(cin, str);// input string
email1=str+s; //generate email by appending input string and given
string
cout<<"Generated email is:
"<<email1<<endl;//print string
return 0;
}
Output 1:
Part A Screenshot
Program in c++ part B:
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
string s="@gwmail.gwu.edu";// given string
string str;
string email;
cout<<"Please Enter a String"<<endl;
getline(cin, str);// input string
int len;
len=str.length(); // find length of string
if(len>10){// is length is grater then 10
string str1=str.substr(0,10);// create substring of length 10
email=str1+s;// //generate email by appending string with length 10
and given string
}
else{
email=str+s; //generate email by appending input string and given
string
}
cout<<"Generated email is: "<<email<<endl;//
print string
return 0;
}
Output 1:
Part B Screenshot