Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include #include using namespace std; const int WORD_MAX_LENGTH = 25; const int LINE_MAX_LENGTH = 50; int main() { //Declaring variables int rows

#include

#include

#include

#include

#include

using namespace std;

const int WORD_MAX_LENGTH = 25;

const int LINE_MAX_LENGTH = 50;

int main()

{

//Declaring variables

int rows = 80, cols = 50, temp, i, j;

char grid[rows][cols]; 2day array

char x = 'Y';

char noun[WORD_MAX_LENGTH}, adjective[WORD_MAX_LENGTH],gerund[WORD_MAX_LENGTH];

srand(time(0));

ifstream input;

input.open("haikus.dat");

if (input.fail()) // if haikus.dat does not exist

{

cout

}

else if (input.eof()) // if haikus.dat is empty

{

cout

}

else

{

input >> row >> cols;

for (i = 0; !input.eof() && i

{

input.getline(grid[i],cols);

}

int haikuPick = rand() & (i / 3);

haikuPick = haikuPick * 3;

cout

while (x == 'Y' || x == 'y')

{

cout

cin >> noun;

cout

cin >> adjective;

cout

cin >> gerund;

cout

char line1[50], line2[50], line3[50];

int lineLength = strlen(grid[haikuPick]);

for (i = 0; haikuPick

{

if (grid[haikuPick][i] == '*')

{

break;

}

}

if (i

{

strncpy(line1, grid[haikuPick], i);

line1[i] = '\0';

strcat(line1, noun);

strcat(line1, &(grid[haikuPick][i+1]));

}

lineLength = strlen(grid[haikuPick + 1]);

for (i = 0; haikuPick

{

if (grid[haikuPick][i] == '*')

{

break;

}

}

if (i

{

strncpy(line3, grid[haikuPick + 2], i);

line3[i] = '\0';

strcat(line3, gerund);

strcat(line3, &(grid[haikuPick + 2][i + 2]));

}

cout

cout

cout

cout

cin >> x;

}

cout

}

input.close();

}

image text in transcribed
haikus in our course content and we will use them in one of the files to test our program. It will be fun to CISP 1010, Lab 3, Arrays and C-Strings execute our programs and see what we get Introduction Sample execution This application creates Mad LibTM haikus based upon user input. Welcome to Mad Lib Haikus! Enter a one syllable noun: car Detailed Information Enter a run evilable adjective: yellow The application reads three-line haikus into a two-dimensional array of characters (an array of C-strings, Enter a two syllable gerund (a verb ending in "ing" like "asking"): not C++ string objects) from an input file called haikus. dat. Do not ask the user for this file name. Just open it trying and read its contents into a two-dimensional array. A sample input file with two haikus is shown below. Your Mad Lib Haiku: Flowers sit in * When begins the car Shades of the * tree near And the yellow Crocus blooms * in sunset Trying When begins the * Continue (Y/N) ? y And the * Crocus blooms Enter a one syllable noun: ear any thing Enter a two syllable adjective: fluffy Enter a two syllable gerund (a verb ending in "ing" like "asking"): The asterisk will actually be in the file. They indicate where words that the user enters go in the haiku. walking The asterisk on the first line will be replaces by a one syllable noun and on the second line will be replaced by a Your Mad Lib Haiku: two syllable adjective. These two askterisks will never be the first character of the line. The asterisk on the third Flowers sit in ear lime will always be the first character on the line and will be replaced by a gerund (a verb ending in "ing" suck Shades of the fluffy tree near as "asking") whose first character the program will have to capitalize. The two dimensional array of characters Walking in sunset for the sample input file is shown below. Continue (Y/N) ? N Flower= 3 it Thank you for using Mad Lib Haikus! Shadess It ree Relevance Questions t \\o W h be This program is all about string manipulation such as finding characters in strings and replacing characters in strings. Many programs manipulate strings. One example is a spell checker in a word processor. The functionality of a spell checker is to find words separated by white space and compare those words to any 9 10 known words in a dictionary- Assume that no one line of a haiku will be longer than 30 characters and have space in the array for no 1. What is an example of a program (besides a spell checker) you use that manipulates strings and what is more than 30 haikus from the input file haikus.dat. Since the input file might have more or less than 30 haikus, that functionality? the program code must handle these situations by reading until the end of the file but not reading more than 30 How could we change or add to our program to make it more like an app people might put on their haikus. There will be no partial haikus in the input file. phones, tablets, or other devices? After the program reads the file contents into the two-D array, it should ask the user for a one syllable Rubric noun, a two syllable adjective and a two syllable gerund. The program then randomly selects a haiku, substitutes For any credit on this lab, the program must use an array of C-strings to hold the haikus and have at least the one syllable noun for the first * in the haiku, the two syllable adjective for the second, and the gerund for the two user defined functions besides main third, and prints this new haiku. The program continues asking for words until the user doesn't type Y (or y) to . (10 points) Comments and style continue. (4 points) Relevance questions Error checking is described below. (4 points) Haiku . 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. . Program correctness . If the input file, haikus.dat, is empty, print the following error message and end the program. o (4 points) Constants Haiku file is empty. Please contact the administrator. (6 points) Random haiku selection o (4 points) Non-existent file behavior This lab requires the use of C-string, not C++ string objects. Write and use at least two functions besides o (4 points) Empty file behavior main. Use constants where appropriate. o (10 points) Loop for user to create another haiku and/or quit Finally, each student must submit one haiku to the instructor. This haiku must follow these rules: 1) The (4 points) Capitalization of first character in gerund first line has five syllables with an asterisk in place of a one syllable noun , 2) the second line has seven o (40 points) Haiku creation and output (includes reading haikus from the file into the array) syllables with an asterisk in place of a two syllable adjective, and 3) the third line has five syllables an asterisk in place of a two syllable gerund which is at the beginning of the line. It doesn't have to be "good". It can be (10 points) Miscellaneous funny. It can be anything except offensive/vulgar. No one will know who wrote which one. I will post these

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

Step: 3

blur-text-image

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions