Question

In: Computer Science

Write a program that takes nouns and forms their plurals on the basis of these rules:...

Write a program that takes nouns and forms their plurals on the basis of these rules:

  1. If noun ends in “y”, remove the “y” and add “ies”.

  2. If noun ends in “s”, “ch”, or “sh”, add “es”.

  3. In all other cases, just add “s”.

Print each noun and its plural. Try the following data:

chair dairy boss circus fly dog church clue dish

PROGRAM: C

Solutions

Expert Solution

I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments (read them for better understanding).

Images of the Code:

Note: If the below code is missing indentation please refer code Images

Typed Code:

// including required headers
#include <stdio.h>
#include <string.h>

int main()
{
// A character Array to store Noun
char Noun[100];
// A character Array to store Plural
char Plural[100];
  
// prompt for Nouns
printf("Enter a Noun: ");
// reading a string and storing it in noun
scanf("%s",Noun);
  
// A variable to store Length of Noun
int Length=strlen(Noun);
  
// If the Last character is y
if (Noun[Length-1] == 'y')
{
// Local variable
int i=0;
// Copying Noun into Plural except the last letter
for (i = 0; i < Length-1; i++)
{
// Copying each character
Plural[i] = Noun[i];
}
//Appending the word 'ies'
Plural[i++] = 'i';
Plural[i++] = 'e';
Plural[i++] = 's';
// Appending Null character
Plural[i++] = '\0';
}
// if Noun ends with 's' or 'ch' or 'sh'
else if(Noun[Length-1] == 's' ||
(Noun[Length-2] == 'c' && Noun[Length-1] == 'h') ||
(Noun[Length-2] == 's' && Noun[Length-1] == 'h')
)
{
// Local variable
int i = 0;
// Copying Noun into Plural
for (i = 0; i < Length; i++)
{
// Copying each character
Plural[i] = Noun[i];
}
//Appending the word 'ies'
Plural[i++] = 'e';
Plural[i++] = 's';
// Appending Null character
Plural[i++] = '\0';
}
// in all other cases
else
{
  
// Local variable
int i = 0;
// Copying Noun into Plural
for (i = 0; i < Length; i++)
{
// Copying each character
Plural[i] = Noun[i];
}
// Appending 's'
Plural[i++] = 's';
// Appending Null character
Plural[i++] = '\0';
}
  
//printing Noun and its Plural
printf("%s --> %s\n", Noun, Plural);
return 0;
}
//code ended here

Output:


If You Have Any Doubts. Please Ask Using Comments.

Have A Great Day!


Related Solutions

Forms often allow a user to enter an integer. Write a program that takes in a...
Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9. Ex: If the input is: 1995 the output is: yes Ex: If the input is: 42,000 or any string with a non-integer character, the output is: no PYTHON 3
Forms often allow a user to enter an integer. Write a programthat takes in a...
Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9
Write a program to demonstrate the use of InetAddress. The program takes a list of names...
Write a program to demonstrate the use of InetAddress. The program takes a list of names or IP addresses as command line parameters and prints the name and an IP address of the local host, followed by names and IP addresses of the hosts specified on the command line. use java program
Write a program in Python that - Takes in a gross salary. - If the gross...
Write a program in Python that - Takes in a gross salary. - If the gross salary is above €50.000 taxes are 50%. - If the gross salary is above €25.000 taxes are 25%. - If the gross salary is above €10.000 taxes are 10%. - If the gross salary is below €10.000 there is no tax. - Output the gross salary and the net income. Note: Give the pseudocode of your program.
Write a program in C that takes the length and the integers to be stored in...
Write a program in C that takes the length and the integers to be stored in an array and shifts array by N positions. Example: Input the number of elements to store in the array (max 10) : 5 Input 5 integers to be stored : Index - 0 : 12 Index - 1 : 29 Index - 2 : 68 Index - 3 : 32 Index - 4 : 97 Input number of shifts : 2 Expected Output :...
Write a program that takes two command line arguments at the time the program is executed....
Write a program that takes two command line arguments at the time the program is executed. You may assume the user enters only decimal numeric characters. The input must be fully qualified, and the user should be notified of any value out of range for a 23-bit unsigned integer. The first argument is to be considered a data field. This data field is to be is operated upon by a mask defined by the second argument. The program should display...
Python Program 1: Write a program that takes user input in the form of a string...
Python Program 1: Write a program that takes user input in the form of a string Break up the string into a list of characters Store the characters in a dictionary The key of the dictionary is the character The value of the dictionary is the count of times the letter appears Hint: remember to initialize each key before using Output of program is the count of each character/letter Sort the output by key (which is the character) Python Program...
Write a program that takes two command line arguments at the time the program is executed....
Write a program that takes two command line arguments at the time the program is executed. Both arguments are to be numerical values restricted to 22-bit unsigned integers. The input must be fully qualified, and the user should be notified of any errors with the input provided by the user. The first argument is to be considered a data field. This data field is to be is operated upon by a mask defined by the second argument. The program should...
The program should be written in C++ with comments Write a program that takes graduation rates...
The program should be written in C++ with comments Write a program that takes graduation rates (per 1000 of the population) for North, South, East, West and Central United States. Input the number from each of the regions in a function returning an int with the graduation rate to the main program. Also figure out which region has the highest graduation rate in another function and display the result from inside that particular function. So your function prototypes should be...
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the...
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the following requirements: Reads in a series of positive integers,  one number at a time;  and Calculate the product (multiplication) of all the integers less than 25,  and Calculate the sum (addition) of all the integers greater than or equal to 25. Use 0 as a sentinel value, which stops the input loop. [ If the input is 0 that means the end of the input list. ]...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT