Question

In: Computer Science

In the C programming language, implement the translation from regular English to Euroglish. If the letters...

In the C programming language, implement the translation from regular English to Euroglish. If the letters were uppercase, keep them uppercase in the replacement.

1. Remove one“e”from the end of words that are more than three characters long, if they happen to end in “e”.

2. Change all double letters to a single letter (including double spaces). Do not remove double line spacing (i.e. “\n”).

3. When a word ends in “ed”, change that to just “d”.

Text:

The cat in the hat roamed around the world.
Here is a weird sentence.
We love to code
They fumed and fumed. They laughed and laughed
Better a bird in the hand than two in the tree.

Solutions

Expert Solution

The below program preserves the uppercase letters, removes 'e' from the end of words that are more than three characters long, changes all double letters to a single letter and changes 'ed' with 'd'.

#include <stdio.h>
#include <string.h>

#define MAX_STRINGS 10
#define STRING_LENGTH 50
int main() {
  char strings[MAX_STRINGS][STRING_LENGTH];
  int i, n, len;

  printf("Enter total number of strings: ");
  scanf("%d", & n);

  printf("Enter the strings:\n");

  for (i = 0; i < n; i++) {
    printf("String [%d]: ", i + 1);
    getchar();
    scanf("%[^\n]s", strings[i]);
  }

  for (i = 0; i < n; i++) {

    len = strlen(strings[i]);

    // Removes trailing 'e' at the end with no fullstop at the end
    if (len > 3 && (strings[i][len - 1] == 'e' || strings[i][len - 1] == 'E')) {
      strings[i][len - 1] = '\0';
    }

    // Runs when the last character of the string is '.'
    // Removes trailing 'e' at the end with fullstop at the end
    if (len > 4 && strings[i][len - 1] == '.' && (strings[i][len - 2] == 'e' || strings[i][len - 2] == 'E')) {
      strings[i][len - 2] = '.';
    }

    // Removes double characters
    for (char * p = strings[i], * q = strings[i];* q++;) {
      if ( * p != * q && ++p != q) * p = * q;
    }

    len = strlen(strings[i]);

    // Removes trailing 'ed' with 'e' while preserving capitals
    if (len >= 2 && (strings[i][len - 1] == 'd' || strings[i][len - 1] == 'D') && (strings[i][len - 2] == 'e' || strings[i][len - 2] == 'E')) {
      if (strings[i][len - 1] == 'd')
        strings[i][len - 1] = 'd';
      else
        strings[i][len - 1] = 'D';
      strings[i][len - 1] = '\0';
    }

    // Runs when the last character of the string is '.'
    // Removes trailing 'ed' with 'e' while preserving capitals with fullstop at the end
    if (len >= 3 && (strings[i][len - 1] == '.' && strings[i][len - 2] == 'd' || strings[i][len - 2] == 'D') && (strings[i][len - 3] == 'e' || strings[i][len - 3] == 'E')) {
      if (strings[i][len - 1] == 'd')
        strings[i][len - 1] = 'd';
      else
        strings[i][len - 1] = 'D';
      strings[i][len - 1] = '\0';
    }
  }

  printf("\nStrings are...\n");

  for (i = 0; i < n; i++) {
    printf("String [%d]: %s\n", i + 1, strings[i]);
  }
  return 0;
}

Output:

Enter total number of strings: 5                               
Enter the strings:                                             
String [1]: The cat in the hat roamed around the world.        
String [2]: Here is a weird sentence.                          
String [3]: We love to code                                    
String [4]: They fumed and fumed. They laughed and laughed     
String [5]: Better a bird in the hand than two in the tree.    
                                                               
Strings are...                                                 
String [1]: The cat in the hat roamed around the world.        
String [2]: Here is a weird sentenc.                           
String [3]: We love to cod                                     
String [4]: They fumed and fumed. They laughed and laughe      
String [5]: Beter a bird in the hand than two in the tre.

Note: When code copied from above, student has to replace [NBSP] with space(' ') in the code, if found any.


Related Solutions

In C++ Language English/Spanish Translation Program. Create a menu driven program that translates English to Spanish...
In C++ Language English/Spanish Translation Program. Create a menu driven program that translates English to Spanish and Spanish to English. Your translation program should use arrays for this program. You will need to populate the arrays with the contents of the English and Spanish data files provided. The two files are ordered such that each word in the one file corresponds to the respective translation in the other (i.e.: the first word in the ENG.txt file corresponds to the first...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is a sub class is derived from the Account class and implements the ITransaction interface. There are two class variables i.e. variables that are shared but all the objects of this class. A short description of the class members is given below: CheckingAccount Class Fields $- COST_PER_TRANSACTION = 0.05 : double $- INTEREST_RATE = 0.005 : double - hasOverdraft: bool Methods + «Constructor» CheckingAccount(balance =...
Implement the MSI cache coherence protocol in your favorite programming language (C, C++, Java, python, etc.)....
Implement the MSI cache coherence protocol in your favorite programming language (C, C++, Java, python, etc.). Wikipedia has a nice high level description of the protocol. Consider only one level of cache which is a write back cache. Moreover, assume that there are 4 processing cores working on a single shared memory. To simplify, assume that you are writing the code for only one block of cache and that block can hold 4 different memory locations.
Description: In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language...
Description: In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language to extract all matching patterns (substrings) from a given input DNA sequence string. The alphabet for generating DNA sequences is {A, T, G, C}. Write a regular expression that represents all DNA strings that begin with ‘A’ and end with ‘T’. Note: assume empty string is not a valid string. Design a deterministic finite automaton to recognize the regular expression. Write a program which...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class with public and private members and multiple constructors.  Gain a better understanding of the building and using of classes and objects.  Practice problem solving using OOP. Overview You will implement a date and day of week calculator for the SELECTED calendar year. The calculator repeatedly reads in three numbers from the standard input that are interpreted as month, day of month, days...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
In a c programming Write a program that converts upper case letters to lower case letters...
In a c programming Write a program that converts upper case letters to lower case letters or vice versa: Enter a sentence: What a GREAT movie is! Converted sentence: wHAT_A_great_MOVIE_IS_ Convert all non-alphabetical letters to ‘_’
Programming language is C# A common place to buy candy is from a machine. A new...
Programming language is C# A common place to buy candy is from a machine. A new candy machine has been purchased for the gym , but it is not working properly. The machine sells candies, chips, gum, and cookies. You have been asked to create aprogram for this candy machine so that it can be put into operation. The program should do the following: 1. Show the customer the different products sold by the candy machine. 2. Let the customer...
GPA calculator in C language To understand the value of records in a programming language, write...
GPA calculator in C language To understand the value of records in a programming language, write a small program in a C-based language that uses an array of structs that store student information, including name, age, GPA as a float, and grade level as a string (e.g., “freshmen,” etc.). Note:Code and Output Screenshots
Using the Java programming language: Create and implement a class Car that models a car. A...
Using the Java programming language: Create and implement a class Car that models a car. A Car is invented to have a gasoline tank that can hold a constant max of 12.5 gallons, and an odometer that is set to 0 for a new car. All cars have an original fuel economy of 23.4 miles per gallon, but the value is not constant. Provide methods for constructing an instance of a Car (one should be zero parameter, and the other...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT