473,779 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a program using four arrays of pointers

91 New Member
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
Sep 18 '07 #1
16 5832
kreagan
153 New Member
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
Sep 18 '07 #2
Nkhosinathie
91 New Member
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.
Sep 18 '07 #3
kreagan
153 New Member
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
Sep 18 '07 #4
Nkhosinathie
91 New Member
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.
Sep 19 '07 #5
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
Sep 19 '07 #6
Nkhosinathie
91 New Member
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

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<cstdlib>
  4. #include<ctime>
  5. using namespace std;
  6. #include<string>
  7. int main()
  8.  
  9. {
  10.  
  11.     char arrayNoun[50]="boy,girl,dog,town,car";
  12.  
  13.     char*arraynounPtr=arrayNoun;
  14.  
  15.  
  16.  
  17.     char arrayArticle[50]="the,a,some,any";
  18.     char* arrayarticlePtr=arrayArticle;
  19.  
  20.     char arrayVerb[50]="drove,jumped,ran,walked,skipped";
  21.     char*arrayverbPtr=arrayVerb;
  22.  
  23.  
  24.     char arrayPreposition[50]="to,from,over,under,on";
  25.     char*arrayprepositionPtr=arrayPreposition;
  26.  
  27.  
  28.     srand(time(0));
  29.  
  30.  
  31.         cout<<arrayArticle[a];
  32.         cout<<arrayNoun[a];
  33.          cout<<arrayVerb[a];
  34.          cout<<arrayPreposition[a];
  35.          cout<<arrayArticle[a];
  36.          cout<<arrayNoun[a];
  37.          cout<<endl;
  38.  
  39.  
  40.         return 0;
  41. }
Sep 19 '07 #7
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:

Expand|Select|Wrap|Line Numbers
  1. char arrayNoun[50]="boy,girl,dog,town,car";
  2.  
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
Sep 19 '07 #8
Nkhosinathie
91 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. char arrayNoun[50]="boy,girl,dog,town,car";
  2.  
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?
Sep 19 '07 #9
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
Sep 19 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2257
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
12
10090
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 '
26
2269
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) {
17
3264
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);
34
29903
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.
23
2269
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...
334
11600
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)
6
1668
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;
4
11655
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...
0
10302
Oralloy
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...
0
9925
tracyyun
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...
1
7478
isladogs
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...
0
6723
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();...
0
5372
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...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
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
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.