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 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 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...
1. Write a program in C++ that takes as inputs a positiveinteger n and a...
1. Write a program in C++ that takes as inputs a positive integer n and a positive double a. The function should compute the geometric sum with base a up to the powern and stores the result as a protected variable. That is, the sum is: 1 + ? + ? ^2 + ? ^3 + ? ^4 + ⋯ + ? ^?2.  Write a program in C++ that takes as input a positive integer n and computes the following productsum...
Write a program in JAVA that takes in two words, and then it recursively determines if...
Write a program in JAVA that takes in two words, and then it recursively determines if the letters of the first word are contained, in any order, in the second word. If the size of the first word is larger than the second then it should automatically return false. Also if both strings are empty then return true. YOU MAY NOT(!!!!!!!!!!): Use any iterative loops. In other words, no for-loops, no while-loops, no do-while-loops, no for-each loops. Use the string...
Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
Write a program that contains a function that takes in three arguments and then calculates the...
Write a program that contains a function that takes in three arguments and then calculates the cost of an order. The output can be either returned to the program or as a side effect. 1. Ask the user via prompt for the products name, price, and quantity that you want to order. 2. Send these values into the function. 3. Check the input to make sure the user entered all of the values. If they did not, or they used...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Write a program that takes in a line of text as input, and outputs that line...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH yeH IN C++ PLEASE!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT