Write and test two programs as described below Include a tit

Write and test two programs as described below. Include a title block in each program. Write a program named that uses an enumeration type to create nicknames for people based on their actual names. Your program should define an enumeration type, nicknameType, that has the values SAM, XMAN, TOOLONG, and BABY. It should also have a function that takes as its parameter a string representing a person\'s first name. The function should return a value of type nicknameType. with this return value being determined as follows: If the person\'s name begins with the letters \"Sam\" (for example, Samuel or Samantha), then the function returns the value SAM. Otherwise, if the person\'s name contains an \"X\" or an \"x\" (for example. Xerxes or Axel), then the function returns the value XMAN. Otherwise, if the person\'s name is more than 10 letters long (for example. Bartholomew), then the function returns the value TOOLONG. Otherwise, the function returns the value BABY. Your program\'s main function should prompt the user to enter his name, then call the function described above, and then, based on the return value from that function, display one of the following four messages: I\'ll call you Sam! I\'ll call you X-Man! I\'ll call you Too-long-to-remember-what-your-name-is! I\'ll call you %-Baby ! (Here % should be replaced by the first letter in user\'s name% for example. P-Baby if the user\'s name is Paul or M-Baby if the user\'s name is Mary.) Four sample runs are shown below. Your prompts and outputs should look exactly like this (spelling, punctuation, number format, and so on). What\'s your name? I\'ll call you Saw! What\'s your name? I\'ll call you X-Man: What\'s your name? I\'ll call you Too-long-to-remember-what-your-name-is! what\'s your name? I\'ll call you R-Baby!

Solution

program with sample outputs

#include<stdio.h>

#include<conio.h>

#include<string.h>
#include<iostream.h>
enum nicknameType{SAM,XMAN,TOOLONG,BABY};
char name[20];
char names[][10]={\"SAM\",\"XMAN\",\"TOOLONG\",\"BABY\"};
int nickname(char firstname[20]) //This function going to return enum value based on the compared value

{
   int l;
if(strchr(firstname,\'X\'))
return XMAN;
else
if((l=strlen(firstname))>10)
return TOOLONG;
else
if((strstr(firstname,\"SAM\")))
   return SAM;
else
   return BABY;
}
void main() //This function is going to accept firstname and prints based on returned value
{
   int n;
   clrscr();
   cout<<\"Enter your first name:\";
   cin>>name;
   n=nickname(name);
   switch(n)
   {
       case 0:   cout<<\"I will call you:\"<<names[n];
           break;
       case 1:cout<<\"I\'ll call you X-Man\";
           break;
       case 2:cout<<\"I\'ll call you Too-long-to-remember-what is your name is:\";
           break;
       case 3:cout<<\"I will call you\"<<name[0]<<\"-\"<<\"BABY\";
           break;
   }
   getch();
}

output1:

Enter your firstname:SAMATA

I will call you :SAM

output2:

Enter you firstname:AXEL

I will call you:X-Man

output3:

Enter your first name:BARTGGYRETAAAE

I\'LL call you TOO-long-to-remember-what is your name is:

 Write and test two programs as described below. Include a title block in each program. Write a program named that uses an enumeration type to create nicknames
 Write and test two programs as described below. Include a title block in each program. Write a program named that uses an enumeration type to create nicknames

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site