hi, i'm writing a program that is using 4 arrays of pointers to char,called article,noun,ve rb and preposition.the program should create a sentence by selecting a word at random from each array in the following order:article,n oun,verb preposition,,ar ticle 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 5832
hi, i'm writing a program that is using 4 arrays of pointers to char,called article,noun,ve rb and preposition.the program should create a sentence by selecting a word at random from each array in the following order:article,n oun,verb preposition,,ar ticle 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.
gpraghuram 1,275
Recognized Expert Top Contributor
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;
-
}
JosAH 11,448
Recognized Expert MVP
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?
JosAH 11,448
Recognized Expert MVP
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,w 3 ...,wn". Read it again.
kind regards,
Jos
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 dimensions and the
length of any dimension can be changed at any time). What I currently
plan is to have an abstract base class at the top, to allow
polymorphism, e.g.:
#include "basedefs.h" // Basic data types, e.g. typedef long Integer
|
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 it.
here is the 4 errors.
c:\C++\Ch15\Employee.h(29): error C2440: '=' : cannot convert from
'char ' to 'char '
|
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. this code
would be much appreciated. Thanks.
mwt.
#include <stdio.h>
int add_array(int arr, int arr_size)
{
|
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:
================================================================================
/* A function that returns a pointer-of-arrays to the calling function. */
#include <stdio.h>
int *pfunc(void);
|
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 crippled all the
constructors. So now all the operations and constructors that were
used do is just return BigFloats but no memory is actually accessed at
any point, nor is any allocated. However, when I reenable those parts
of the constructor that...
|
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 clearly be
sufficient. This could lead to unnecessarily bad performance on very
long strings. It is also written in a hard-to-read and clunky style.
char *dot_to_underscore(const char *s)
{
char *t = malloc(strlen(s) + 1);
if(t != NULL)
|
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 to access the data like this:
x->row.coll.value.d;
|
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 the three months.
1. Complete the program by entering the C++ code that allows the user to enter four sets(one set for each region) of three sales amounts (one sales amount for each month). The program should display each region's total sales for...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |