Answered step by step
Verified Expert Solution
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 Lab Arrays and CStrings
For any credit on this lab, the program must use an array of Cstrings 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 threeline haikus into a twodimensional array of characters an array of Cstrings, 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 twodimensional 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
S h a d e i f t h e t r e e n e a r
i n s u n s e t
W h e n b e g i n s t h e
A n d t h e c r o c u s b l o o m s
a n y t h i n g
Assume that no one line of a haiku will be longer than characters and have space in the array for no more than haikus from the input file haikus.dat. Since the input file might have more or less than haikus, the program code must handle these situations by reading until the end of the file but not reading more than haikus. There will be no partial haikus in the input file.
After the program reads the file contents into the twoD 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 nonexistent. 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 Cstring, 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: The first line has an asterisk in place of a noun, the second line has an asterisk in place of an adjective, the third line has an asterisk in place of a gerund which is at the beginning of the line, no line is longer than characters, and write your own haiku. It doesnt have to be good It can be funny. It can be anything except offensivevulgar 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 nonexistent. 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 YN 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 YN N
Thank you for using Mad Lib Haikus!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started