Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help!! some of the testcases are failing and i dont know why. Here is the question: Write a program in C++.Prompt the user for

please help!! some of the testcases are failing and i dont know why.

Here is the question:

Write a program in C++.Prompt the user for his/her first name. Output the user's nickname. Use this algorithm to generate a nickname:

If the first letter in the user's name is odd according to the ASCII chart, output "Big" followed by the first three letters of the name.

If the first letter in the user's name is even according to the ASCII chart, output "Lil" followed by the first four letters of the name.

Here is my code:

#include #include using namespace std; //Returns true if the given string only contains letters

//Returns false otherwise

bool verify(string name)

{

//assume that all characters in the string are letters

bool valid_string = true;

for(int subscript = 0; subscript < name.length(); subscript++)

{

if (isdigit(name[subscript]))//if (the current character is a digit)

valid_string = false;//this string is no longer valid

else if(ispunct(name[subscript]))//if (the current character is a punct)

valid_string = false;//this string is no longer valid

}

//go back to where we left off -- bring the result

return valid_string; } int main() { string name; cout << "Enter your first name" << endl; cin >> name; if (verify(name)) { cout << "Your nickname is:" <

Required output: (The wrong outputs that are mine are marked with 3 stars)

Standard Input
Andrew 

Required Output

Enter your first name Your nickname is: Big And 

Your Program's Output

Enter your first name Your nickname is: Big And 

Test Case 2 - Failed

Standard Input
Barney 

Required Output

Enter your first name Your nickname is: Lil Barn 

Your Program's Output ***

Enter your first name Your nickname is: Big Bar  (Your output is too short.) 

Test Case 3 - Passed!

Standard Input
Cammy 

Required Output

Enter your first name Your nickname is: Big Cam 

Your Program's Output

Enter your first name Your nickname is: Big Cam 

Test Case 4 - Failed

Standard Input
Daniel 

Required Output

Enter your first name Your nickname is: Lil Dani 

Your Program's Output ***

Enter your first name Your nickname is: Big Dan  (Your output is too short.) 

Test Case 5 - Passed!

Standard Input
Eddie 

Required Output

Enter your first name Your nickname is: Big Edd 

Your Program's Output

Enter your first name Your nickname is: Big Edd 

Test Case 6 - Passed!

Standard Input
Michael 

Required Output

Enter your first name Your nickname is: Big Mic 

Your Program's Output

Enter your first name Your nickname is: Big Mic 

Test Case 7 - Passed!

Standard Input
Stuart 

Required Output

Enter your first name Your nickname is: Big Stu 

Your Program's Output

Enter your first name Your nickname is: Big Stu 

Test Case 8 - Failed

Standard Input
Xerxes 

Required Output

Enter your first name Your nickname is: Lil Xerx 

Your Program's Output ***

Enter your first name Your nickname is: Big Xer  (Your output is too short.) 

Test Case 9 - Failed

Standard Input
Yasmine 

Required Output

Enter your first name Your nickname is: Big Yas 

Your Program's Output ***

Enter your first name Your nickname is: Lil Yasm 

Test Case 10 - Passed!

Standard Input
Zenith 

Required Output

Enter your first name Your nickname is: Lil Zeni 

Your Program's Output

Enter your first name Your nickname is: Lil Zeni 

Test Case 11 - Passed!

Standard Input
And+rew 

Required Output

Enter your first name Only letters are allowed. 

Your Program's Output

Enter your first name Only letters are allowed. 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago