Respuesta :
Answer:
def name_facts(firstname):
print("Your name is",len(firstname),"letters long",end=", ")
if(firstname[0] == 'A'):
print("does start with the letter A",end=", ")
else:
print("does not start with the letter A", end=", ")
if(firstname.count('Z')>0 or firstname.count('X')>0):
print("and does not contain a Z or X")
else:
print("and does not contain a Z or X")
#Testing
name_facts("Allegra")
name_facts("Xander")
Explanation:
Answer:
// Comments are used for explanatory purpose
// Program starts here
#include<iostream>
using namespace std;
int main()
{
// Declare firstname
string firstname;
//Prompt to enter firstname
cout<<"What's your first name: ";
// Accept input
cin>>firstname;
// A. Get string's length
int length = firstname.length();
// Print length
cout<<"Length = "<<length<<endl;
// Copy string to chat array
char char_array[length + 1];
// copying the contents of the string to char array
strcpy(char_array, firstname.c_str());
// B. Check if it starts with letter A
if(char_array[0] == 'A')
{
cout<<"Your Firstname begins with letter A"<<endl;
}
else
{
cout<<"Your Firstname doesn't begin with letter A"<<endl;
}
// Check if it contains X or Z
int k = 0;
for (int i = 0; i < n; i++) {
if(char_array[i] == 'Z' || char_array[i] == 'X')
{
k++;
}
if(k == 0)
{cout<<"Your Firstname doesn't contain Z or X";}
else
{cout<<"Your Firstname contains Z or X";}
}
return 0;
}