Question

Problem A: Word Shadow Source file: shadow.cpp f or java, or.cj Input file: shadow.in in reality, when we read an English word we normally do not read every single letter of that word but rather the words shadow recalls its pronunciation and meaning from our brain. The words shadow consists of the same number of letters that compose the actual word with first and last letters (of the word) in their original positions while the rest of letters are interchanged symmetrically as shown in Figure 1; for example the sentence I love programming still can be read if it is written as I lvoe pnimmargorg. Your task is to write a program that reads a set of sentences each of which is composed of a number of words; for each sentence, the program should produce another sentence which contains the exact number of words in their shadow form progr ammi n gPn immar g or g actual word shadow word Example of conversion of a word to its shadow word Input In a single execution, the program should run for T test cases. The first line of the input file contains the integer variable T. The rest of the T lines that follow, each contains two pieces of information about one sentence; the number of words (W) in the sentence and the text of the sentence itself. The variable W ranges from 1 to 10 inclusive. Each word may contain up to 12 letters. There is exactly one space between any two consecutive words in a sentence and sentences are entirely in small letters and do not contain any punctuation mark or special characters Output Your program should produce for each test case, a sentence written in shadow format; words that are composed of less than four letters do not have shadow and if the number of letters composing a word is odd and more than four, the position of the central letter remains unchanged. Sample Input Sample Output 7 if anything can go wrong it will 8 a thing of beauty is a joy forever a tnihg of btuaey is a joy feveror if anihtyng can go wnorg it wlilplease write a C++ code

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<fstream>
#include <ctype.h>
#include<sstream>
// #include<bits/stdc++>


using namespace std;
int main(){
   int ctr=0;
   ifstream fin;
   fin.open("text.txt"); //opening the file

   while(!fin.eof()){
      
       string line;
       getline(fin,line,'\n'); //getting each line in the text file
       if(ctr==0){
           ctr++;
           continue;
       }else{
           stringstream ss(line);
           string word;
           while(ss>>word){
               if(word.length()<3){ //if word length is less than 3 then we will skip the word and if it numeric then also we skip it
                   if(isdigit(word.at(0))){
                       continue;
                   }
                   cout<<word<<" ";
               }else{
                   int i=0;
                   int j=word.length()-1;
                   char arr[word.length()-1];
                   arr[i]=word.at(0);
                   arr[j]=word.at(word.length()-1);
                   i++;
                   j--;
                   while(i<=j){ //reversing the number from 1 and length -2 position as described in the question
                       arr[i]=word.at(j);
                       arr[j]=word.at(i);
                       i++;
                       j--;
                   }
                   for(int i=0;i<=sizeof(arr)/sizeof(arr[0]);i++){ //displaying each word after reading it immediately
                       cout<<arr[i];
                   }
                   cout<<" ";
               }
           }
       }
       cout<<"\n";

   }
   fin.close(); //closing a file
   return -1;
}

Add a comment
Know the answer?
Add Answer to:
please write a C++ code Problem A: Word Shadow Source file: shadow.cpp f or java, or.cj...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program Description: A Java program is to be created to produce Morse code. The Morse code...

    Program Description: A Java program is to be created to produce Morse code. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. In a sound-oriented...

  • I dont understand how to solve these type of questions. Q2. (25 marks) Write a C++...

    I dont understand how to solve these type of questions. Q2. (25 marks) Write a C++ program that takes a sentence as input (type string) and returns what follows. Structure your program using functions. 1. The number of characters 2. The number of words in the sentence 3. The number of proper words (any word that starts with a capital letter except the first word) 4. The number of words that contain two consecutive letters (e.g., "letter”)

  • JAVA PROGRAMMING (Game: hangman) Write a hangman game that randomly generates a word and prompts the...

    JAVA PROGRAMMING (Game: hangman) Write a hangman game that randomly generates a word and prompts the user to guess one letter at a time, as shown in the sample run. Each letter in the word is displayed as an asterisk. When the user makes a correct guess, the actual letter is then displayed. When the user finishes a word, display the number of misses and ask the user whether to continue to play with another word. Declare an array to...

  • You are given a set of ABC cubes for kids (like the one shown below) and a word. On each side of ...

    You are given a set of ABC cubes for kids (like the one shown below) and a word. On each side of each cube a letter is written 7 FI 0 You need to find out, whether it it possible to form a given word by the cubes For example, suppose that you have 5 cubes: B1: MXTUAS B2:OQATGE ВЗ: REwMNA B4: MBDFAC В5: IJKGDE (here for each cube the list of letters written on its sides is given) You...

  • Program Description: A C# app is to be created to produce Morse code. The Morse code...

    Program Description: A C# app is to be created to produce Morse code. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. In a sound-oriented...

  • I need help writing this C code. Here is the description: Let's say we have a...

    I need help writing this C code. Here is the description: Let's say we have a program called smart typing which does two things: The first letter of a word is always input manually by a keystroke. When a sequence of n letters has been typed: c1c2...cn and the set of words in the dictionary that start with that sequence also have c1c2...cnc then the smart typing displays c automatically. we would like to know,  for each word in the dictionary,...

  • Use C++ and Visual Studio Word Finder Version Your version of word finder should allow players...

    Use C++ and Visual Studio Word Finder Version Your version of word finder should allow players to find as many words as they can from the list of letters. Name the cpp file called wordFinder LastNameFirstName.cpp. Words must contain at least 3 letters but no more than 6 letters The program must first read the words from a file but only can read in at most 5 words from a text file. The program should skip words that contains less...

  • Program is in C++. Write a function named wordStatsPlus that accepts as its parameter a string...

    Program is in C++. Write a function named wordStatsPlus that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report: the total number of lines; total number of words; the number of unique letters used from A-Z, case-insensitively, and its percentage of the 26-letter alphabet; the average number of words per line (as an un-rounded...

  • Program is in C++.   Write a function named wordStatsPlus that accepts as its parameter a string...

    Program is in C++.   Write a function named wordStatsPlus that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report: the total number of lines; total number of words; the number of unique letters used from A-Z, case-insensitively, and its percentage of the 26-letter alphabet; the average number of words per line (as an un-rounded...

  • Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And...

    Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And also I have codes but just donot work so make sure that it works. Requested files: CrosswordGenerator.cpp, CrosswordGenerator.h, CrosswordGenerator_test.cpp CrosswordGenerator - Write a program that helps to generate a crossword puzzle by organizing words that share letters.   For this assignment, you will write a program that forms the basis of a crossword puzzle generator. In order to create a crossword puzzle you need to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT