New to programming and need help with assignment.

Hey everyone, this is my first time posting in this forum and i was hoping you guys could help me to write this program for my class.

This is the assignment:

-----------------------------------------------------------------------------

+--------------+
| Program |
string Token# | |
--------------->| tokens |--------> Token#
| |
+--------------+

NOTE: ONE input line contains a string of tokens.
MULTIPLE output lines containing one or more tokens.


Definition: A "token" is a sequence of characters surrounded by whitespace.
"Whitespace" is a blank/space, tab, blank line or end-of-line.


Example: The phrase, "The slow, fat, dog is pretty!" contains tokens
The
slow,
fat,
dog
is
pretty!


----------------------------------------------------------------------------
PART I. READING & WRITING TOKENS.
----------------------------------------------------------------------------

Algorithm:

1. Prompt user to enter ONE sentence containing at least six (6) tokens.

2. Read six tokens into string variables tok1, tok2, ..., tok6.

3. Output the six tokens, one per line, numbered, in the format:

Required output format
-----------------------
1: token1 1: The
2: token2 2: slow,
...
6: token6 6: pretty!


4. Output the six tokens, two per line that begins with the '|' (vertical
bar) character; each token preceded by ONE tab.


Required output format
------------------
| token1 token2 | The slow,
| token3 token4 | fat, dog
| token5 token6 | is pretty!


5. Output the six tokens, three per line. Each line begins with the '>'
character, followed by three fields of widths 6, 8 and 5, respectively,
with left, left, and right justification, respectively, and
ends with the '<' character.


Required output format
------------------
>xxxxxxyyyyyyyyzzzzz< (field markers)
> tok1 tok2 tok3< >The slow, fat, <
> tok4 tok5 tok6< >dog is pretty!<



6. Output the six tokens ALL ON ONE LINE, with one space separating
tokens.

Example: The input line: "Never in a million light years."

Required output format: 'Never in a million light years.'
-------------------------------------------------------------------------

We are doing it in the unix environment, and honestly im not sure where to start. So far i have written:

#include <iostream>
using namespace std;

int main()
{

}.
start at

1. Prompt user to enter ONE sentence containing at least six (6) tokens.
would that be cout >> "enter one sentence containing at least six tokens. " >> ?
closed account (3TkL1hU5)
Either you have been severely slacking on your part or you need to fire your teacher.

honestly, probably a little bit of both. Just trying to get on track now before the semester gets out of hand.
check syntax for cout
so far ive gotten:

#include <iostream>
using namespace std;

int main()
{

//-----------------------------------------------------------------------------
// Prompt to enter one sentence containing at least six tokens
//------------------------------------------------------------------------------

cout << " Enter one sentence containing at least six tokens. " <<;

//-------------------------------------------------------------------------------
// Read six tokens into string variables tok1, tok2,..., tok6.
//-------------------------------------------------------------------------------
string tok1,
tok2,
tok3,
tok4,
tok5,
tok6
i thought i had it figured out but its not compiling, any comments? :

#include <iostrean>
#include <iomanip>
using namespace std;

int main()
{
//-| ---------------------------------------
//-| Declare Variables
//-| --------------------------------------
string tok1, // First Token
tok2, // Second Token
tok3, // Third Token
tok4, // Fourth Token
tok5, // Fifth Token
tok6, // Sixth Token

//-| ------------------------------------------------------------------------
//-| 1. Prompt user to enter ONE sentence containing at least six (6) tokens.
//-| ------------------------------------------------------------------------
cout << "Enter one sentence containing at least six tokens." << endl;

//-| ------------------------------------------------------------------------
//-| 2. Read six tokens into string variables tok1, tok2,..., tok6.

//-| Declare Variables
//-| --------------------------------------
string tok1, // First Token
tok2, // Second Token
tok3, // Third Token
tok4, // Fourth Token
tok5, // Fifth Token
tok6, // Sixth Token

//-| ------------------------------------------------------------------------
//-| 1. Prompt user to enter ONE sentence containing at least six (6) tokens.
//-| ------------------------------------------------------------------------
cout << "Enter one sentence containing at least six tokens." << endl;

//-| ------------------------------------------------------------------------
//-| 2. Read six tokens into string variables tok1, tok2,..., tok6.
//-| ------------------------------------------------------------------------
cin >> tok1
>> tok2
>> tok3
>> tok4
>> tok5
>> tok;

//-| ------------------------------------------------------------------------
//-| 3. Output the six tokens, one per line, numbered, in the format:
//-|
//-| Output pattern Sample output
//-| -------------- ------------------------
//-| 1: token1 1: The
//-| 2: token2 2: slow,
//-| ...
//-| 6: token6 6: pretty!
cin >> tok1
>> tok2
>> tok3
>> tok4
>> tok5
>> tok;

//-| ------------------------------------------------------------------------
//-| 3. Output the six tokens, one per line, numbered, in the format:
//-|
//-| Output pattern Sample output
//-| -------------- ------------------------
//-| 1: token1 1: The
//-| 2: token2 2: slow,
//-| ...
//-| 6: token6 6: pretty!
//-| ------------------------------------------------------------------------
cout.width(14);
cout << "1: " << tok1;
cout << "2: " << tok2;
cout << "3: " << tok3;
cout << "4: " << tok4;
cout << "5: " << tok5;
cout << "6: " << tok6;



okay i got it to compile but this is the result: 1: The2: slow,3: fat,4: dog5: is6: pretty!

anyone know why?

heres my code:


#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
//-| ---------------------------------------
//-| Declare Variables
//-| --------------------------------------
string tok1, // First Token
tok2, // Second Token
tok3, // Third Token
tok4, // Fourth Token
tok5, // Fifth Token
tok6; // Sixth Token

//-| ------------------------------------------------------------------------
//-| 1. Prompt user to enter ONE sentence containing at least six (6) tokens.
//-| ------------------------------------------------------------------------
cout << "Enter one sentence containing at least six tokens." << endl;

//-| ------------------------------------------------------------------------
//-| 2. Read six tokens into string variables tok1, tok2,..., tok6.
//-| ------------------------------------------------------------------------
cin >> tok1
>> tok2
>> tok3
>> tok4
>> tok5
>> tok6;

//-| ------------------------------------------------------------------------
//-| 3. Output the six tokens, one per line, numbered, in the format:
//-|
//-| Output pattern Sample output
//-| -------------- ------------------------
//-| 1: token1 1: The
//-| 2: token2 2: slow,
//-| ...
//-| 6: token6 6: pretty!
cin >> tok1
>> tok2
>> tok3
>> tok4
>> tok5
>> tok6;

//-| ------------------------------------------------------------------------
//-| 3. Output the six tokens, one per line, numbered, in the format:
//-|
//-| Output pattern Sample output
//-| -------------- ------------------------
//-| 1: token1 1: The
//-| 2: token2 2: slow,
//-| ...
//-| 6: token6 6: pretty!
//-| ------------------------------------------------------------------------
cout << "1: " << tok1;
cout << "2: " << tok2;
cout << "3: " << tok3;
cout << "4: " << tok4;
cout << "5: " << tok5;
cout << "6: " << tok6;

return 0;
}
Because you did..

1
2
3
4
5
6
cout << "1: " << tok1;
cout << "2: " << tok2;
cout << "3: " << tok3;
cout << "4: " << tok4;
cout << "5: " << tok5;
cout << "6: " << tok6;


Change "1: " to just " ".
Last edited on
1
2
3
4
5
6
cout << "1: " << tok1 << endl;
cout << "2: " << tok2 << endl;
cout << "3: " << tok3 << endl;
cout << "4: " << tok4 << endl;
cout << "5: " << tok5 << endl;
cout << "6: " << tok6 << endl;


Use that if you want an output that contains multiple lines instead of just one line
Topic archived. No new replies allowed.