Question

IN C++ Write a program in c++ that will read from a file the following sentence:...

IN C++ Write a program in c++ that will read from a file the following sentence: The quick brown fox jumps over the lazy dog Each word must be read into one location in an array beginning with the first element. You must declare an array as follows: char *words [9] ; // this is an array of c- strings. HINT words[0] will contain "the" words[1] will contain "quick" write a function int length (const char *a) to determine the length of each string by incrementing the pointer until we find the null character '\0'. Once you have determined hte length of each string, fill the following arrays as follow: char *t3[[ ] = {"the", ... char *t4 [ ] = {"quick", "brown", ... where a each number is the length of the string ( not counting the null character). continue adding each string to its respective array ( t3, t4, ...) until you have reached the end of the array called words.Do not use 2dimensional arrays. Finally, print all words of each arrayvertically seperated by a blank line

The

T

h

e

Quick

q

u

i

c

k

ect....

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

ANSWER:

#include <iostream>

#include <fstream>

using namespace std;

int length(const char *arr)

{
   int len = 0;

   while(arr[len] != '\0')

   {
       len++;
   }

   return len;
}

int main()

{
   ifstream inFile("input.txt");
char *words[9];

int i = 0;

   char temp[10][10];

   while(inFile)

    {
       words[i] = new char[10];

       inFile >> words[i];

       i++;
    }

   for(i = 0; i < 9; i++)

{
       cout << words[i] << "\n";

       for(int j = 0; j < length(words[i]); j++)

      {
           cout << words[i][j] << "\n";
       }
   }
}

Add a comment
Know the answer?
Add Answer to:
IN C++ Write a program in c++ that will read from a file the following sentence:...
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
  • C++ Write a MyString class that stores a (null-terminated) char* and a length and implements all...

    C++ Write a MyString class that stores a (null-terminated) char* and a length and implements all of the member functions below. Submit your completed source (.cpp) file. Default constructor: empty string const char* constructor: initializes data members appropriately Copy constructor: prints "Copy constructor" and endl in addition to making a copy Move constructor: prints "Move constructor" and endl in addition to moving data Copy assignment operator: prints "Copy assignment" and endl in addition to making a copy Move assignment operator:...

  • I/O program for C Write a program in direct1.c which reads from standard input a line...

    I/O program for C Write a program in direct1.c which reads from standard input a line and then outputs that line immediately to standard output. it should read the first line only ! Then, write another program called direct2.c which reads from standard input every line until end of input and outputs them to standard output. Everything that goes in should come out exactly as it was. Compile both programs and run them on the input files given below The...

  • Simple Python Program Working with strings Write a Python program to read in a number of...

    Simple Python Program Working with strings Write a Python program to read in a number of strings from the user. Stop when the user enters “Done”. Then check if each of the strings contains all the letters of the alphabet. Print the results in the form of a dictionary, where they keys are the strings and the values are the Truth Value for the string, which you just calculated. Sample Run: Enter the strings: taco cat The quick brown fox...

  • Python 3:Write a program that inputs a text file. The program should print the unique words...

    Python 3:Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order.   Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order An example file along with the correct output is shown below: example.txt the quick brown fox jumps over the lazy dog Enter the input file name: example.txt brown dog fox jumps lazy over quick the

  • i am trying to write a subroutine in assembly that removes all occurrences of a given...

    i am trying to write a subroutine in assembly that removes all occurrences of a given character in a string. The subroutine takes two parameters: the string pointer, and the character to be removed. Write a C code that calls this subroutine. The string is defined in the C source code file as global. Assume the assembly and C code are in separate files. Use Keil/uVision to test your program where the C code should ask the assembly subroutine to...

  • -Brief description of the program: - input(s) and output(s) - brief description or relationship b...

    -Write in C++ language. -Brief description of the program: - input(s) and output(s) - brief description or relationship between inputs and outputs Submission Instructions: Submit only.c files in the designated Dropbox on D2L Problem 1 (25 points): Write a C program that a) reads one line (sentence) at a time from a text file called inputtext.txt (on D2L), b) reverses the words on that line, c) prints (on the screen) the modified line and d) write the modified line in...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • Using the website Repl.it Write a Java program that can perform the Caesar cipher for English...

    Using the website Repl.it Write a Java program that can perform the Caesar cipher for English messages that include both upper and lowercase alphabetic characters. The Caesar cipher replaces each plaintext letter with a different one, by a fixed number of places down the alphabet. The program should be able to shift a specific number of places based on the user's input number. For example Plaintext: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG. Ciphertext: QEBNRFZH YOLTK CLU GRJMP...

  • using c only You will read in two strings from a file cp4in_1.txt at a time...

    using c only You will read in two strings from a file cp4in_1.txt at a time (there will be 2n strings, and you will read them until EOF) and then do the following. You alternately take characters from the two strings and string them together and create a new string which you will store in a new string variable. You may assume that each string is no more than 20 characters long (not including the null terminator), but can be...

  • Write a program in LEGv8 assembly to copy a null-terminated ASCII string from array y to array x;...

    Write a program in LEGv8 assembly to copy a null-terminated ASCII string from array y to array x; converting every 'a' character in the source string to 'b' in the destination string. In other words, for each character in array y: else Assume that the base address of the arrays x and y are in registers X0 and X1, respectively. The ASCII code for characters 'a' and 'b' is 113 and 114 respectively [25 pts]. * Null-terminated means that a...

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