Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CISP 1 0 1 0 , Lab 3 , Arrays and C - Strings For any credit on this lab, the program must use an

CISP 1010, Lab 3, Arrays and C-Strings
For any credit on this lab, the program must use an array of C-strings to hold the haikus, read haikus from an input file, and have at least two user defined functions besides main.
Introduction
This application creates Mad Lib haikus based upon user input.
Detailed Information
The application reads three-line haikus into a two-dimensional array of characters (an array of C-strings, not C++ string objects) from an input file called haikus.dat. Do not ask the user for this file name. Just open it and read its contents into a two-dimensional array. A sample input file with two haikus is shown below.
Kind * holding hands
In the warm, * daylight
* together.
My * is nice
Full of * energy
* in circles.
The asterisks will actually be in the file. They indicate where words that the user enters go in the haiku. The asterisk on the first line will be replaces by a one syllable noun and on the second line will be replaced by a two syllable adjective. These two asterisks will never be the first character of the line. The asterisk on the third line will always be the first character on the line and will be replaced by a gerund (a verb ending in ing such as asking) whose first character the program will have to capitalize. The two dimensional array of characters for the sample input file is shown below.
F l o w e r s s i t i n *\0
S h a d e i f t h e * t r e e n e a r \0
* i n s u n s e t \0
W h e n b e g i n s t h e *\0
A n d t h e * c r o c u s b l o o m s \0
* a n y t h i n g \0
Assume that no one line of a haiku will be longer than 50 characters and have space in the array for no more than 30 haikus from the input file haikus.dat. Since the input file might have more or less than 30 haikus, the program code must handle these situations by reading until the end of the file but not reading more than 30 haikus. There will be no partial haikus in the input file.
After the program reads the file contents into the two-D array, it should ask the user for a one syllable noun, a two syllable adjective and a two syllable gerund. The program then randomly selects a haiku, substitutes the one syllable noun for the first * in the haiku, the two syllable adjective for the second, and the gerund for the third, and prints this new haiku. The program continues asking for words until the user doesnt type Y (or y) to continue.
Error checking is described below.
If the input file, haikus.dat, does not exist, print the following error message and end the program.
Haiku file non-existent. Please contact the administrator.
If the input file, haikus.dat, is empty, print the following error message and end the program.
Haiku file is empty. Please contact the administrator.
This lab requires the use of C-string, not C++ string objects. Write and use at least two functions besides main. Use constants where appropriate.
Finally, each student must submit one haiku to the instructor. This haiku must follow these rules: 1) The first line has an asterisk in place of a noun, 2) the second line has an asterisk in place of an adjective, 3) the third line has an asterisk in place of a gerund which is at the beginning of the line, 4) no line is longer than 50 characters, and 5) write your own haiku. It doesnt have to be good. It can be funny. It can be anything except offensive/vulgar. No one will know who wrote which one. I will post these haikus in our course content and we will use them in one of the files to test our program. It will be fun to execute our programs and see what we get!
Sample executions
Welcome to Mad Lib Haikus!
Haiku file non-existent. Please contact the administrator.
Thank you for using Mad Lib Haikus!
Welcome to Mad Lib Haikus!
Enter a one syllable noun: car
Enter a two syllable adjective: yellow
Enter a two syllable gerund (a verb ending in ing like asking): trying
Your Mad Lib Haiku:
When begins the car
And the yellow Crocus blooms
Trying any thing
Continue (Y/N)? y
Enter a one syllable noun: ear
Enter a two syllable adjective: fluffy
Enter a two syllable gerund (a verb ending in ing like asking): walking
Your Mad Lib Haiku:
Flowers sit in ear
Shades of the fluffy tree near
Walking in sunset
Continue (Y/N)? N
Thank you for using Mad Lib Haikus!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

1. Describe the types of power that effective leaders employ

Answered: 1 week ago