Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in c++ programming code Define a character array named nameArray that contains t

ID: 3721230 • Letter: I

Question

in c++ programming code

Define a character array named nameArray that contains the first 7 letters of your full name as the array's elements in sequence. For e.g., for someone named Jon. P. Doe, the variable should be: char nameArrayll ['J, 'o', 'N','P,'D'O, 'E'H; Please make sure to represent your full legal name (as it appears in your Baruch college registration records) and use all uppercase characters. If your full name has more than 7 letters, take the first 7 letters. If your full name has less than 7 letters, pad it by repeating characters. For. e.g. if your name is Xu Li, pad it like so: {'X','U','L','I','X'.'U'L'y

Explanation / Answer

#include <iostream>

using namespace std;


int main()
{
string name;
char nameArray[8];
int c=0;
cout<<"Enter the full name: "<<endl;
getline(cin , name);
while(c<7){
for(int i=0;i<name.length() && c<7;i++) {
char ch = toupper(name[i]);
if(ch>='A' && ch<='Z') {
nameArray[c++]=ch;
}
}
}
nameArray[c]='';
cout<<"Char Name array: "<<endl;
for(int j=0;j<c;j++){
cout<<nameArray[j]<<" ";
}
cout<<endl;
return 0;
}

Output: