EECS168 09:Homework7

From ITTC
Jump to: navigation, search
Navigation
Home
Information

Syllabus
Schedule
Lecture Notes
Exam Reviews

Classwork

Labs
Homework
Submitting Work


Overview

You are going to write a program that takes a string as input from the user and reverses each word in the received string using pointers and stores the completely modified string in a dynamic array of char type and output the modified array to the terminal.
DUE DATE: The electronic submission of your homework must be received before 11:59 pm, Sunday, 26th of April.

Problem Description and Program Requirements

1. Write a program stringReverse.cpp.
2. The program takes a string as an input.
3. The program should use two pointers front and rear.
4. The front pointer should initially reference the first character of a word in the string, and the rear pointer should initially reference the last character of a word in the string.
5. Reverse the word of the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the preceding character, and so on, until the entire word is reversed.
6. Repeat steps 4 and 5 until all the words in the string are reversed.
7. Store the modified string in a dynamic array of char type.
8. Output the contents of the dynamic array (which has fully modified string).

Example Program Execution

Enter the string: THIS IS HOMEWORK7 OF EECS168
The formatted String is: SIHT SI 7KROWEMOH FO 861SCEE

Notes

  • Your source code files should have comments at the top with:
    • your name
    • the class ("EECS 168")
    • the assignment name (i.e., "Homework 7")
    • the date
    • an explanation of what the code is supposed to do
  • You should have comments in the code that explain what the code is doing.

Additional Requirements For EECS 169 Students

  • Allow the program to jumble the words in the input string. The jumbling order should be as given in the sample execution below

Example Execution:
Enter the string: THIS IS HOMEWORK7 OF EECS168
The jumbled string is: EECS168 OF HOMEWORK7 IS THIS
The formatted String is: SIHT SI 7KROWEMOH FO 861SCEE

Submission

The files you should submit electronically (in a tarball) are:

  • stringReverse.cpp: Your source code.
  • testing.txt: The testing you did on your finished stringReverse.cpp program. Test your code for both even and odd length strings.