hi, i'm writing a program that is using 4 arrays of pointers to char,called article,noun,verb and preposition.the program should create a sentence by selecting a word at random from each array in the following order:article,noun,verb preposition,,article and noun.as each word is picked,it should be concatenated to the previous words in an array that is large enough to hold the entire sentence. the words should be separated by spaces.when the final sentence is output,it should start with a capital letter and end with a period.the program should generate 20 such sentences.
what i have deduced from this statement is that ill be using 4 arrays of pointers.so may you help me to have an idea of where to start because i don't have an idea.thanks
16 5763
hi, i'm writing a program that is using 4 arrays of pointers to char,called article,noun,verb and preposition.the program should create a sentence by selecting a word at random from each array in the following order:article,noun,verb preposition,,article and noun.as each word is picked,it should be concatenated to the previous words in an array that is large enough to hold the entire sentence. the words should be separated by spaces.when the final sentence is output,it should start with a capital letter and end with a period.the program should generate 20 such sentences.
what i have deduced from this statement is that ill be using 4 arrays of pointers.so may you help me to have an idea of where to start because i don't have an idea.thanks
Are you an extremely new to the language? Why are you stucked?
At any rate, I would suggest simplifying the problem down into sections:
1.) Generate/Initialize array of pointers
2.) Get 1 value from each array
3.) Genrate string from pieces of array
4.) Capitalize first character and place period at the end
5.) Store into array of size 20
6.) Print
7.) Repeat 19 more times.
Good luck
Are you an extremely new to the language? Why are you stucked?
At any rate, I would suggest simplifying the problem down into sections:
1.) Generate/Initialize array of pointers
2.) Get 1 value from each array
3.) Genrate string from pieces of array
4.) Capitalize first character and place period at the end
5.) Store into array of size 20
6.) Print
7.) Repeat 19 more times.
Good luck
this is my first year programming in c++ but i now know the basics of it but my problem now is we haven't done arrays and pointers that's why i'm stucked.
this is my first year programming in c++ but i now know the basics of it but my problem now is we haven't done arrays and pointers that's why i'm stucked.
Well, then I would suggest reading about arrays and pointers. Here's some good links. Arrays and Pointers More Arrays and pointers
Read section 2.2. The diagram shows an array and a pointer to an array.
To make the problem simplier, try combining just 4 words together by using pointers then printing them out. After you have done that, worry about creating the array of pointers, choosing the 4 words, and storing them.
Good luck
Kat
i'm so sorry to repeat this statement,i thought maybe you guys u don't understand this program that i'm doing.
i'll post the code i have done for this program because this program is driving me crazy right now
Write a program that uses random number generation to create sentences. The program should use four arrays of pointers to char called article, noun, verb, and preposition. The program should create a sentence by selecting a word at random from each array in the following order: article noun verb preposition article noun. As each word is picked, it should be concatenated to the previous words in an array which is large enough to hold the entire sentence. The words should be separated by spaces. When the final sentence is output, it should start with a capital letter and end with a period. The program should generate 20 such sentences.
The arrays should be filled as shown below.
article noun verb preposition
the boy drove to
a girl jumped from
one dog ran over
some town walked under
any car skipped on
Turn in your source code listing and a print out of the output screen showing
the result. Your program must be modular and fully commented.
i'm so sorry to repeat this statement,i thought maybe you guys u don't understand this program that i'm doing.
i'll post the code i have done for this program because this program is driving me crazy right now
Write a program that uses random number generation to create sentences. The program should use four arrays of pointers to char called article, noun, verb, and preposition. The program should create a sentence by selecting a word at random from each array in the following order: article noun verb preposition article noun. As each word is picked, it should be concatenated to the previous words in an array which is large enough to hold the entire sentence. The words should be separated by spaces. When the final sentence is output, it should start with a capital letter and end with a period. The program should generate 20 such sentences.
The arrays should be filled as shown below.
article noun verb preposition
the boy drove to
a girl jumped from
one dog ran over
some town walked under
any car skipped on
Turn in your source code listing and a print out of the output screen showing
the result. Your program must be modular and fully commented.
Why cant you post your code u have written and explain which part of the code u are facing issues?
Raghuram
Why cant you post your code u have written and explain which part of the code u are facing issues?
Raghuram
this is the code i managed to do.my problem now is where can i place the random function inorder for the program to print different sentences -
#include<iostream>
-
#include<iomanip>
-
#include<cstdlib>
-
#include<ctime>
-
using namespace std;
-
#include<string>
-
int main()
-
-
{
-
-
char arrayNoun[50]="boy,girl,dog,town,car";
-
-
char*arraynounPtr=arrayNoun;
-
-
-
-
char arrayArticle[50]="the,a,some,any";
-
char* arrayarticlePtr=arrayArticle;
-
-
char arrayVerb[50]="drove,jumped,ran,walked,skipped";
-
char*arrayverbPtr=arrayVerb;
-
-
-
char arrayPreposition[50]="to,from,over,under,on";
-
char*arrayprepositionPtr=arrayPreposition;
-
-
-
srand(time(0));
-
-
-
cout<<arrayArticle[a];
-
cout<<arrayNoun[a];
-
cout<<arrayVerb[a];
-
cout<<arrayPreposition[a];
-
cout<<arrayArticle[a];
-
cout<<arrayNoun[a];
-
cout<<endl;
-
-
-
return 0;
-
}
So you have all your nouns in a single char array separated by commas. The
same applies to the verbs, articles etc. Let's take the noun array for example: -
char arrayNoun[50]="boy,girl,dog,town,car";
-
If there are 'n' commas in that single string there are 'n+1' nouns in that string.
So you need to generate a pseudo random number 'r' in the range [0, n] (inclusive).
Next you have to skip 'r' commas and copy the next noun upto the 'r+1'st
comma.
Check the available functions in the <cstring> library or the <string> library.
I'm sure you can make good use of some of them.
kind regards,
Jos
So you have all your nouns in a single char array separated by commas. The
same applies to the verbs, articles etc. Let's take the noun array for example: -
char arrayNoun[50]="boy,girl,dog,town,car";
-
If there are 'n' commas in that single string there are 'n+1' nouns in that string.
So you need to generate a pseudo random number 'r' in the range [0, n] (inclusive).
Next you have to skip 'r' commas and copy the next noun upto the 'r+1'st
comma.
Check the available functions in the <cstring> library or the <string> library.
I'm sure you can make good use of some of them.
kind regards,
Jos
i'm really sorry i don't understand what u mean?
i'm really sorry i don't understand what u mean?
That was a short outline of the steps you have to implement in order to produce
a (pseudo) random element from a list "w0,w1,w2,w3 ...,wn". Read it again.
kind regards,
Jos
That was a short outline of the steps you have to implement in order to produce
a (pseudo) random element from a list "w0,w1,w2,w3 ...,wn". Read it again.
kind regards,
Jos
please check the following code. -
// program uses randon number generation to create sentences
-
#include <iostream>
-
#include <stdlib.h>
-
#include <time.h>
-
#include<ctype.h>
-
#include<cstring>
-
const int row= 20;
-
-
const int column= 80;
-
void touppercase(char *string);
-
void concatenate(char *array[][column],int element,char *string[],int size);
-
-
using std::cout;
-
using std::endl;
-
-
int main()
-
{
-
-
srand(time(NULL));
-
-
char *array[row][column] = {" "};
-
int position= 0;
-
int counter= 1;
-
char *article[5]= {"the","a","one","some","any"};
-
char *noun[5]= {"boy","girl","dog","town","car"};
-
char *verb[5]= {"drove","jumped","ran","walked","skipped"};
-
char *preposition[5]= {"to","from","over","under","on"};
-
-
do
-
{
-
-
-
if(counter == 20)
-
touppercase(article[position]);
-
-
concatenate(array,counter,article,row);
-
-
concatenate(array,counter,noun,row);
-
-
concatenate(array,counter,verb,row);
-
-
-
concatenate(array,counter,preposition,row);
-
-
-
}while(counter < 21);
-
for(int i =0;i<20;i++)
-
for(int j =0;j<20;j++)
-
cout<<array[i][j]<<endl;
-
-
return 0;
-
}
-
-
void touppercase(char *string)
-
{
-
int i =0;
-
while((*string != '\0') && (i != 1))
-
{
-
*string = toupper(*string);
-
++i;
-
}
-
}
-
void concatenate(char *array[][column],int element, char *string[],int size)
-
{
-
int position = 0;
-
position = rand() % 5;
-
array[element][column] = string[position];
-
-
}
So now you've changed the implementation from this: -
char arrayNoun[50]="boy,girl,dog,town,car";
-
to this: -
char *noun[5]= {"boy","girl","dog","town","car"};
-
That renders my remarks, based on your previous implementation, completely useless.
kind regards,
Jos
Heya, Nkhosinathie.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Nkhosinathie-
Please do not double-post - try to keep all your questions on the same topic in one thread.
Also, you are a member, so you should be using code tags around your code. They are [CODE=cpp] and [/code].
Thanks
Heya, Nkhosinathie.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
the program doesn't want to print anything. when i compile it,it shows just a space
thanks.
Nkhosinathie-
Please do not double-post - try to keep all your questions on the same topic in one thread.
Also, you are a member, so you should be using code tags around your code. They are
.
Thanks
i apologise for that,and i'm still not sure how to wrap my code to code tags.
i apologise for that,and i'm still not sure how to wrap my code to code tags.
If you look at my post above, you put the code in the space of the 'and' in between the two tags. Then if you look at your reply, you will see how the code is translated.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brian McGuinness |
last post by:
I have a question about using the STL transform algorithm in a function.
What I want to do is define a group of array classes to represent
APL-style arrays (arrays in which the number of...
|
by: GRoll35 |
last post by:
I get 4 of those errors. in the same spot. I'll show my parent class,
child class, and my driver.
All that is suppose to happen is the user enters data and it uses
parent/child class to display...
|
by: mwt |
last post by:
Hello. Today I wrote my first program in C. It adds up the elements in
an array. I am just beginning to learn this language. Any tips or
pointers about better ways to write/structure/format/etc....
|
by: I.M. !Knuth |
last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until
I started goofing around with this:
...
|
by: Tom |
last post by:
I'd greatly appreciate advice and code snippets on how to create a ram
disk within a C/C++ program.
I also need to be able to determine the free space.
Thanks in advance for any help.
|
by: mike3 |
last post by:
Hi.
I seem to have made some progress on finding that bug in my program. I
deactivated everything in the bignum package that was used except for
the returning of BigFloat objects. I even...
|
by: Antoninus Twink |
last post by:
The function below is from Richard HeathField's fgetline program. For
some reason, it makes three passes through the string (a strlen(), a
strcpy() then another pass to change dots) when two would...
|
by: jason |
last post by:
Hello,
I have a question about what kind of datastructure to use. I'm reading
collumn based data in the form of:
10\t12\t9\t11\n
24\t11\t4\t10\n
.....
I now have a structure which allows me...
|
by: wutang |
last post by:
Create a program that displays the sum of the sales amounts made in each of four regions (North, South, East, West) during a three month period. The program should display the total sales made during...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |