Clinton Portis 211 Practically a Posting Shark

The above code you have for original >> extracting words from your text file will only work 'word at a time', until it hits a white space.

Therefore, a word like "10 Speeds" will be put into two separate str[] objects.

One way to get around this, is to use the getline() function. This would work good for your file anyway, because individual words are contained on their own line.

//instead of
original >> str[i];

//try this:
getline(original, str[i]);

You mentioned that, "some words get doubled." It may be because you are testing for eof() in your loop, which would necessitate an extra loop interation before the eof() flag is set to TRUE. Instead, just test the return value of getline(), which will return TRUE if the extraction was successful, else will return FALSE if extraction unsucessful (which would occur at end of file):

//insted of this
while(!original.eof())

//try this:
while(getline(original, str[i]))

Also here, I notice you are trying to use the < operator on two string objects. While this is fine whilst performing boolean logic among individual characters of the string, I do not see anywhere in the <string> class documentation where the < is overloaded to make comparisons between strings. However, I will make a suggestion to help get you pointed in the right direction:

//str[i] resovles to a single string
if(str[i]>str[i+1])

//need to go one step futher to get to individual characters of the string
if(str[i][j]>str[i+1][j])

Since we are at …

Clinton Portis 211 Practically a Posting Shark

jst m not able to think how to exrtract data from string..

We can use our standard string parsing algorithm. In this case, we can use find_first_of() since we will have multiple delimeters (+, -, *, and / for example)

string expression = "5+104-32/5";
string terms[20];
int prev=-1, curr=-1; 

while(curr_pos != string::npos)
{     
     prev_pos = curr_pos;     
     curr_pos = find_first_of("+-*/", prev_pos+1);      

     if(curr_pos != string::npos)           

          terms[i] = expression.substr(prev_pos+1, (curr_pos - prev_pos)); 
}

You can learn about other <string> class member here that will help you with your parsing needs.

Hope this helps to point ye' in the right direction. This is a basic string parsing algorithm for <string> class objects. This is untested code and may contain easy to fix errors.

Clinton Portis 211 Practically a Posting Shark

Talk about resurrecting the dead on Halloween.. never seen a post this old get bumped to the top in a long time (this thread originated back in 2004!)

Clinton Portis 211 Practically a Posting Shark

I just want to say that I love the title of this thread and I hope it stays at the top for awhile.

Clinton Portis 211 Practically a Posting Shark

I think your mind was still focused on that Halloween candy. :)

Clinton Portis 211 Practically a Posting Shark

you could probably do something like this:

int total = 0;

for(int counter=0; counter < i; counter++)
{
     total += product[counter].price;
}

cout << "Total goods sold is:  " << total;

Good looking well coded program btw. The only critique I have is that I would probably use a struct over a class, mainly because struct access is automatically made 'public' whereas with classes you have to use an extra line of code to change access to public.

Also, one mistake here:

}while(answer == 'y' || answer == 'Y' && answer !='N'&&'n');

//should be
}while((answer == 'y' || answer == 'Y') && (answer != 'N' || answer !='n'));

Although if you test for Y, you know your only other option would be N, so why even test for N...

Also, line #57 does not need to exist, because if you fall through the do/while loop, you can assume that the user no longer wants to input data and you can just continue with the rest of the program.

Clinton Portis 211 Practically a Posting Shark

you can easily perform a test on an entire range of values:

//If 'x' is greater than or equal to 1 AND 'x' is less than or equal to 380
if(x >= 1 && x <= 380)
{
     //Do amazing things
}
Clinton Portis 211 Practically a Posting Shark

this seems to work, I'll try it and let you know the results, but now its Halloween!!

Trick-or-Code (I think we all know the obvious answer to this question...)

Clinton Portis 211 Practically a Posting Shark

I need the DeAnza, CA, and FL to be already in an array without the user input.

Ok, I think we are narrowing this down here...

Just try something like this:

station[0].StationDesignation = "DeAnza, CA";
station[1].StationDesignation = "Naples, FL";
station[2].StationDesignation = "Buffalo, NY";
Clinton Portis 211 Practically a Posting Shark

I need the object (STATES) to be populated w/o the user input.

I am still not sure what you mean by this. The struct object has no attribute named 'states'.

In order to populate your structs, you will have to prompt the user for input.

I have provided a previous example of how you can provide the user a specific prompt for each state in which the related struct is to be populated.

If you would like to add additional information to your struct, such as the state, this attribute could possibly be loaded via comparison to an existing data database of information according to let's say, the station designation (for example, station id N70FX3 is located in california, and we could assign 'California' to a <string> attribute of your struct).

Please be very specific with your requests.

Clinton Portis 211 Practically a Posting Shark

Is there anyway to assign CA, FL, and NY to an array WITHOUT having to type them in?

I am not sure what you mean by this, but in my previous two examples, I prompted the user for input and then tested the input to make high/low determinations.

Edit: Ok, I think I know what you mean now.. you want to display specifcially which state you are entering instead of my generic prompts for user information.

Let's throw a little switch( ) action inside of our loop in order to customize our prompts for user input:

char ans;
int i=0; 

     do{      

               switch(i)
               {

                    case 1:  cout << "\nEnter data for CA:  ";     
                                 cin >> station[i].StationDesignation;  
                                 cin >> station[i].Temperature;
                                 break;    

                   case 2: cout << "\nEnter data for FL:  ";     
                               cin >> station[i].StationDesignation;   
                               cin >> station[i].Temperature;   
                               break;

                  case 3: cout << "\nEnter data for NY:  ";
                              cin >> station[i].StationDesignation;
                              cin >> station[i].Temperature;
                              break;

                 default:  cout << "\a\nInvalid Entry! ";
                               cin.get();
                               break;
     
          cout << "\nWould you like to enter another station?  (Y/N) ";     
          cin >> ans;      

          i++;      

}while(ans == 'Y' || ans == 'y');
Clinton Portis 211 Practically a Posting Shark
Clinton Portis 211 Practically a Posting Shark

This is a common topic and very necessary for your CS academic career.

First, create your object:

struct WeatherStation{      

     string StationDesignation;     
     double Temperature;     
};

Now create a bunch of them. For your assignment, I think you only need 3 of them:

//creates array elements [0] thru [2]
     WeatherStation stations[3];

Now populate your 'station' objects:

char ans;
int i=0;

do{

     cout << "\nEnter Station Designation:  ";
     cin >> station[i].StationDesignation;

     cout << "\nEnter Station Temperature:  ";
     cin >> station[i].Temperature;

     cout << "\nWould you like to enter another station?  (Y/N) ";
     cin >> ans;

     i++;

     }while(ans == 'Y' || ans == 'y');

Now that your 3 'station' objects are populated, you can now sort the array. I'm in a fiesty mood today, so I'll use the swap( ) function from <algorithm>:

for(int i=0; i<2; i++)
{
     if(station[i].Temperature > station[i+1].Temperature)

          swap(&station[i+1], &station[i]);
}

Now your 3 'station' objects are sorted by their temperature attribute to ascending order (lowest to highest), so you know that station[0] will be the struct with the lowest temperature, and station[2] will be the struct with the highest temperature.

Also, I hope you can see how much code we have saved just by using an array data structure. It allows us to do the same things over and over via the use of loops and common array operations.

This is untested code and may contain easy to fix errors. If anyone knows of a better way to do this, please let us know.

Clinton Portis 211 Practically a Posting Shark

If you were using an array of structs, I would simply just tell you to sort the array based on the desired struct attribute, and simply pick off the struct at the begging and at the end of the array.

But since this is not the case, the best technique I can think of will be to make the high/low determination as soon as you accept user input (based on previous user input).

To do this, I am going to add a couple of flags to your struct. These flags will be initially set to FALSE, but will be set to TRUE anytime the struct qualifies for highest or lowest, and will be set back to FALSE whenever it no longer qualifies as the highest or lowest.

For this example, I will be using the 'temperature' attribute of the struct:

struct WeatherStation {

     bool highest;
     bool lowest;
     string StationDesignation;
     double Temperature;

     //Inline Constructor
     WeatherStation(){highest = FALSE;  lowest = FALSE;}
}CA, FL, NY;

string input;
int high=-200, low=200;

//Caleeforneeaah       
cout << "\nEnter California station designation:  ";
cin >> CA.StationDesignation;
cout >> "\nEnter California temperature:  ";
cin >> CA.Temperature;

if(CA.Temperature > high)
{
     high = CA.Temperature;
     CA.highest = TRUE;     
}
else if(CA.Temperature <low)
{
     low = CA.Temperature;
     CA.lowest = TRUE;
}

//Pablo honey, come to Florida...
cout << "\nEnter Florida station designation:  ";
cin >> FL.StationDesignation;
cout >> "\nEnter Florida temperature:  ";
cin >> FL.Temperature;

if(FL.Temperature > high)
{
     high = FL.Temperature;
     FL.highest = TRUE;
     CA.highest = FALSE: …
Clinton Portis 211 Practically a Posting Shark

Error - Line #5 of my alphabetizing algorithm, should be:

for(int j=0; j<words[[B]i[/B]].size() && j<words[[B]i[/B]+1].size(); j++)
Clinton Portis 211 Practically a Posting Shark

Based on limited information and very little code, I will make some assumptions and hopefully offer a solution that makes some sort of sense.

First, I will assume that all 3 words you wish to alphabetize are part of the same string (named 'x'). I will also assume you have 1 white space seperating the words in your string.

If all this is true, I would recommend parsing the string up into 3 individual substrings (words), perform comparisons among these strings in order to determine alphabetical order; and if desired, return all the substrings back into the original string:

#include<string>
#include<algorithm>
#include<cctype>

string x = "Benny Sun Honey";
string words[3];
int prev=-1, curr=-1;

while(curr_pos != string::npos)
{
     prev_pos = curr_pos;
     curr_pos = find(' ', prev_pos+1);
     
     if(curr_pos != string::npos)
          
          words[i] = x.substr(prev_pos+1, (curr_pos - prev_pos));
   
}

Now that you have your three individual words (words[3]), you can test them individually:

for(int i=0; i<2; i++)
{
     for(int j=0; j<words[j].size() && j<words[j+1].size(); j++)
     {        
          if(toupper(words[i][j]) < toupper(wordsl[i+1][j]))
          {
               break;
          }

          else if(toupper(words[i][j]) > toupper(wordsl[i+1][j]))
          {
               swap(words[i], words[i+1]);
               break;
           }
     } 
}

Now if you want, you can return all 3 words (words[3]) back into your original x <string>:

for(int i=0; i<3; i++)
{
     x += words[i] + ' ';
}

Let me know if this is anywhere in the ballpark of what you needed to do.

This code is untested and may contain easy to fix errors. Also, if anyone knows of a better way to do …

Clinton Portis 211 Practically a Posting Shark

Here is your insert node function:

void insertWord (ifstream& wordIn, wordRec *letters [], int& index, string& word, int& wrdIndex)
{
     wordRec *head = NULL;     
     wordRec *newNode = NULL;
     
     if (head == NULL) 
     {
          newNode = new (nothrow) wordRec;
          newNode->newWord = word;
          newNode->previous = NULL;
          newNode->next = newNode;

     if (head != NULL)

          head->previous = newNode;

     head = newNode;
     letters[index] = head;
     letters[index]->next = head;
     letters[index]->previous = head;

wordListPlacement (wordIn, letters, index, wrdIndex); 
}

the code in red (above) I have a problem with, because you initialize a 'head' pointer to NULL at the beginning of your function, and then immediately perform a test to see if head == NULL, which will always be the case.

In your wordlist placement function, you have a bunch of the same stuff over and over... why not put it in a loop:

for(int i=0; i<26; i++)
{
     if (wrdIndex == [B]i[/B]) 
     {
          count++;
          letters[[B]i[/B]] = head;
          cout << count << " A words: " << letters[[B]i[/B]]->newWord << endl;
     }
}

Other than that, let me offer some simple pseudo code for node insertion into a double linked list:

*In a double-linked list, always keep a dedicated head pointer and tail pointer.

1. create a new node
2. populate the node with stuff
3. perform a list traversal to see where to put the new node. In this case, we traverse the list until we find a spot prior to where we want to insert:

//start from the …
Clinton Portis 211 Practically a Posting Shark

I am really unclear about what you are trying to accomplish...

If you want to sort strings alphabetically, I can help you with some simple code.

If you want to campare two strings, you could use the string class overloaded == equality test.

If you are trying to compare two elements (letters) of a string, you could also use the == equality test.

Clinton Portis 211 Practically a Posting Shark

:D

Clinton Portis 211 Practically a Posting Shark

Oh ok, I see what you are saying....

What I would do then, is to keep your prompt for user input inside of your do/while loop to populate your array...

Then take your 'for' loop out and place it after the do/while to display all the array contents.

Clinton Portis 211 Practically a Posting Shark
for (x = 0; x<15; x++)
{    
     storage[x] = number;    cout << storage[x] << " " << endl;    
     [b]break;[/b]
}

the rest of your code looks pretty good i have to say.

Clinton Portis 211 Practically a Posting Shark
#include<windows.h>
#include<sstream>
#include<string>
using namespace std;

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "calculator";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "calculator",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           257,                 /* The programs …
Clinton Portis 211 Practically a Posting Shark

how do i get the average of average?

add up all the tests and divide by the total number of tests.

Clinton Portis 211 Practically a Posting Shark

I would read from the text file and store the contents of the .txt file into some sort of a container; probably a <string> class object.

Once you have your string container(s) populated, loop through the string(s) and keep two counter variables that will increment any time a string == "Heads" or string == "Tails".

ifstream infile;
string results[100];

int heads=0, tails=0;


int i=0;
while(infile >> results[i])
{
     if(results[i] == "Heads")
     {
          heads++;
     }
   
     else
     {
          tails++;
     }
   
     i++;
}
Clinton Portis 211 Practically a Posting Shark

I have a feeling you may have place program output inside of a loop.

Let us see ye' code.

Clinton Portis 211 Practically a Posting Shark

51 is the ascii value of the character '3'....

Knowing this, we can now we can put some of that advanced college education to work:

ascii value - x = int

51 - x = 3

x = 48

After you make your char-to-int cast, just subtract 48. (This offset will apply to all ascii numeric characters)

Clinton Portis 211 Practically a Posting Shark
Clinton Portis 211 Practically a Posting Shark
b = static_cast(a);

should be:

b = static_cast<int>(a);
Clinton Portis 211 Practically a Posting Shark
int counter=0;

while(...)
{
     ...
     ...
     ...
    counter++
}

cout << "The while() loop executed " << counter << " times.";
Clinton Portis 211 Practically a Posting Shark

i am in need to change my char to int.

You are in luck.. char to int conversions are wicked easy..

(and so is any conversion among c++ standard primitive data types)

Most people like to use the old c-style cast because it's quick and easy although technically it's not c++:

char a = 'A';
int b;

// b will contain the numerical ascii value of capital letter 'A'
b = (int)a;

Now here is the technically correct c++ method:

char a = 'A';
int b;

b = static_cast<int>(a);
Clinton Portis 211 Practically a Posting Shark

I can't read any of that C code.

Clinton Portis 211 Practically a Posting Shark

I believe ye' problemo might be here:

//Here you declare 'int counter = -10'
int counter = -10;

//Here you delcare an array[10] (creates elements 0 thru 9)
int xyMax = 10;   
int xData[xyMax];   
int yData[xyMax];

//Here you attempt to access array elements less than array[0]
for (counter; counter <= xyMax; counter ++) 
{        
     xData[counter] = NULL; // Clear the vars        
     yData[counter] = NULL; //        
}
Clinton Portis 211 Practically a Posting Shark

This is what should be running through your head:

1. create an ifstream object
2. attempt to open a .txt file
3. perform error checking to see if file actually opened (may not exist)
4. If open, read in .txt file into <string> class containers
5. close the ifstream object (no longer needed)
6. using the <sstream> library, perform string-to-int convesions
7. perform desired math
8. display stuff to screen
9. exit program


Now turn your thoughts into c++

#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
using namespace std;

int main()
{ 
     
     string student_name[20], test1[20], test2[20], test3[20];
     int iTest1[20], iTest2[20], iTest3[20], iAverage[20];

     //1.  create an ifstream object
     ifstream inFile;

     //2.  attempt to open a .txt file
     inFile.open("C:\\myprograms\\documents\\sample.txt");

     //3.  perform error checking to see if file actually opened 
     if(!inFile.open())
     {
          cout << "\a\nUnable to open file!  (does the file exist?) ";
          cin.get(); 
          exit(1);
     }

     //4.  If open, read in .txt file into <string> class containers
     int i=0;
     while(inFile >> student_name[i] >> test1[i] >> test2[i] >> test3[i])
     {
          i++;
     {

     //5.  close the ifstream object (no longer needed; free up resources)
     inFile.close();

     //6. perform string-to-int converstions
     i=0;
     do{  
        
               istringstream str_to_int(test1[i]);
               str_to_int >> iTest1[i];

               istringstream str_to_int(test2[i]);
               str_to_int >> iTest2[i];

               istringstream str_to_int(test3[i]);
               str_to_int >> iTest3[i];

               i++;

     }while(!test1[i].empty());

     //7.  perform desired math
     for(int i=0; i<test1[0].size(); i++)
     {
          iAverage[i] \= (iTest1[i] + iTest2[i] + iTest3[i]);
     }

     //8.  display stuff to screen
     i=0;
     do{
              cout << "\n\nName:  "  << student_name[i] << "     " 
                   << "\nTest …
Clinton Portis 211 Practically a Posting Shark

1. create an ifstream object
2. attempt to open a .txt file
3. perform error checking to see if file even exists
4. read in the entire file to an array of strings
5. close the ifstream object
6. using the <sstream> library create a ostringstream object
7. perform string-to-int conversions on the elements of the string array you wish to use
9. perform desired operations "add and divide numbers"
10. exit program

Clinton Portis 211 Practically a Posting Shark

I would study the <windows.h> library for your GUI needs.

Clinton Portis 211 Practically a Posting Shark

any suggestions?

Show us the code?

Clinton Portis 211 Practically a Posting Shark

I just want to say that the deque class reminds me of Dairy Queen teehee.

Clinton Portis 211 Practically a Posting Shark

Error - Line #6, Should be:

bool deq_test(Str& deq1, Str& deq2){Return (deq1.a < deq2.a);}
Clinton Portis 211 Practically a Posting Shark

That looks like quite a time investment.. cool ascii art too.

How long did all this take you..??!?

Clinton Portis 211 Practically a Posting Shark

Let me offer this suggestion:

Using the sort() function from <algorithm> we find that there is an overloaded version of sort() that will allow us to supply our own custom-made 'test' function. Let's use this in order to specifically perform a test between two 'deques of structs'. We'll base our test on the 'int a' attribute of the struct:

Here are the two versions of sort():

template <class RandomAccessIterator>
  void sort ( RandomAccessIterator first, RandomAccessIterator last );

template <class RandomAccessIterator, class Compare>
  void sort ( RandomAccessIterator first, RandomAccessIterator last, Compare comp };

The version we will be using is in green (above).

#include<algorithm>
#include<deque>
#include<ctime>
...
...
bool deq_test(Str& deq1, Str& deq2){Return (deq1.a < deq2.b);}
...
Str MyStr;
...
srand(time(NULL));
...
//Randomly populate ye' deque
for(int i=0; i<6; i++)
{
     MyStr.a = rand()%10;
     MyStr.b = rand()%10;

     deq.push_back(MyStr);
}
...
//Deque sorting goodness
sort(deq.begin(), deq.end(), deq_test);

//Now your deque is sorted according to the 'int a' Str struct attribute in ascending order.

The above code is untested and also I have never done this before but according to the instructions all this should work bueno.

Let me know how this works for ye' if you decide to use this.

Clinton Portis 211 Practically a Posting Shark

What are you trying to do... your entire post doesn't make a lick of sense.

Clinton Portis 211 Practically a Posting Shark

The requirements for this assignement approach an intermediate level of programming since we cannot use arrays or <string> class objects. Being that we are unable to use arrays, we cannot use 'c-strings' (char arrays). So what's left?

Our options include: STL containers and linked lists or just create a ton of singular char variables and hope we have enough for user input. Another option would be to write all the char variables to a file.

I'm open to suggestions, I think the method I used was probably the most primitive of options that I could think of.

Clinton Portis 211 Practically a Posting Shark

Try this and see if it works for ye'...

std::string& write();

std::string& test::write()
{	
          std::string *name = "HELLO";
          return name:
}
Clinton Portis 211 Practically a Posting Shark

line #24 should be: list->next = new node;

Clinton Portis 211 Practically a Posting Shark

can only use nested loops NO arrays or strings

I was kinda stumped at first until I came up with a linked-list of chars:

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

struct node
{
     char letter;
     node *next;
};

int main()
{
     node *head_ptr = new node;
     node *list = head_ptr;
     int counter = 0;
     char input, ans;

     do{

               cout << "\nEnter a letter:  ";
               cin >> input;

               list->letter = toupper(input);      
               list->next = new list;
               list = list->next;

               counter++;

               cout << "\nWould ye' like to enter another letter? (Y/N) ";
               cin >> ans;                     

          }while(toupper(ans) == 'Y');

          list->next = NULL;
          list = head_ptr;

          int j=1;
          while(list)
          { 
               for(int i=0;  i<j && list; i++)
               {
                    cout << list->letter; 
                    list = list->next;
               }

               cout << endl;
               j++;
          }

         list = head_ptr;
         node temp;

          while(list)
          {
               temp = list;
               list = list->next;
               delete temp;               
          }         

return 0;
}

This code creates a 'linked-list' of nodes that contain space for 1 char per node. After the user is prompted to enter several letters, the list is traversed (starting from the head pointer) and displayed to the screen in a tree type manner.

This is untested code, so it might contain simple/easy to fix errors.

Clinton Portis 211 Practically a Posting Shark

in line #8, you no longer need to typedef a second time... just go ahead and create your object:

addr a;
Clinton Portis 211 Practically a Posting Shark

Here is a quick poor man's method:

int elements = sizeof(serviceinfo) / sizeof(serviceinfo[0]);
Clinton Portis 211 Practically a Posting Shark

In this block of code, you only make one call to 'infile' your data. You should consider infile'ing your data whilst inside of a loop to ensure you will read in data until you reach end of file:

you have this:

else
{	
     //This code to read data only gets called once, therefore only reading one line o' data
     inFile >>stuId>>gr1>>gr2>>gr3>>gr4;
}

To correct this, turn your grade variables into arrays that will store data per each loop iteration:

double gr1[10] ,gr2[10] ,gr3[10] ,gr4[10], GPA[10];
//we could have also just made a single gr[4][10]
					
int i=0;
while(inFile >> stuId[i] >> gr1[i] >> gr2[i] >> gr3[i] >> gr4[i])
{
     i++;	
}

Now you can read in several lines at a time because your loop structure will allow you to extract several lines of data.. until such time data can no longer be extracted (end of file). You also have the appropriate number of storage containers to handle all of the data; into 10 element arrays, one element for each student (one for each line of .txt).

Clinton Portis 211 Practically a Posting Shark

so my question is how do i center the first line ?

From what I understand, you are wanting to center a line of text on the dos console screen.

Assuming that the standard screen will support 80 characters, we can derive the following formula:

40 - (string length / 2) = where you should start outputting your text in order to have a centered appearance.

We can also use the setw() function from <iomanip> to help us with our centering needs:

#include<iomanip>
#include<string>
#include<iostream>

string temp;
int spaces = 0;

if(flip < 2)
{
     temp =+ 'H';
}
else
{
     temp =+ 'T';
}

     spaces = 40-(temp.length() / 2);
     cout << setw(spaces) << temp;

So to summarize our code, we first perform a boolean test to determine which block of code to perform; if flip < 2 then 'H' else 'T'. We then use the plus/equals =+ operator to 'concantinate' (or accumulate) an array of H's and T's into a <string> class object. We then perfrom simple math to determine an offset of the midpoint of our screen in which to start outputting text. We used the setw() function (from <iomanip>) to set the number of preceding white spaces. We use the length() string member function to return the number of characters in the string.

Clinton Portis 211 Practically a Posting Shark

Here is suggested pseudo code for what ye' want to accomplish:

1. create an ifstream object (for opening & reading from file)
2. create an ofstream object (to write to the file)
3. open the source .txt file
4. perform error checking (see if file opened properly & if it even exists)
5. read in your text file (preferably line-by-line for this project using getline())
6. populate an array of strings[3] (each element will hold a line of text)
7. close the ifstream object
8. Prompt for user input
9. Peform desired operations on the string[3] array (based on stored user input)
9. Write string[3] to the .txt file
10. close ofstream object