David W 131 Practically a Posting Shark

You may like to try this C 'readLine' emulation of C++ 'getline' ...

/* CppToC_via_readLine.h.c */

/* using readLine to emulate C++ getline ... */

#include "readLine.h"

/* get copy of file: "readLine.h" at this next link  ... */

/*
  http://developers-heaven.net/forum/index.php/topic,2580.msg2864.html#msg2864

*/

char encode( char plaintext )
{
    if( isupper(plaintext) )
    {
        if( plaintext > 'M' ) plaintext += 13;
        else plaintext -= 13;
    }
    else if( islower(plaintext) )
    {
        if( plaintext > 'm' ) plaintext +=13;
        else plaintext -=13;
    }
    return plaintext;
}


int main()
{
    char* str;
    unsigned i;

    printf( "Input string: " ); fflush( stdout );

    str = readLine( stdin ); /*free dynamic memory*/

    for( i = 0; i < strlen( str ); ++ i )
        printf( "%c", encode( str[i] ) );

    free( str ); /*now can free dynamic memory*/

    printf( "\n\nPress any <ENTER> to exit ... " );
    getchar();
    return 0;
}
David W 131 Practically a Posting Shark

This may give you some ideas ...

/*  structPoint.c */

#include <stdio.h>
#include <ctype.h> /* re. tolower */

typedef struct
{
    int x, y;
} Point ;

void printPoint( const Point* p )
{
    printf( "(%d, %d)  ", p->x, p->y ) ;
}
void printPoints( const Point ary[], int size )
{
    int i;
    for( i = 0; i < size; ++ i )
    {
        printPoint( &ary[i] ) ;
        putchar( '\n' );
    }
}

char takeInChar( const char* msg )
{
    char chr;
    printf( msg ); fflush( stdout );
    chr = getchar();
    if( chr != '\n' ) while( getchar() != '\n' ) ; /* flush stdin ... */
    return chr;
}
int more() /* defaults to 'true'/'yes'/'1' ... unless 'n' or 'N' entered */
{
    if( tolower( takeInChar( "More (y/n) ? " )) == 'n' ) return 0;
    /* else ... */
    return 1;
}


int main()
{
    Point locations2[] =
    {
        {100,200},
        {210,320}
    } ;
    Point locations3[] =
    {
        {100,200},
        {210,320},
        {410,120}
    } ;


    do
    {
        switch( takeInChar( "Choose '2' or '3' (enter 2 or 3) : " ) )
        {
            case '2' : printPoints( locations2, 2 ); break;
            case '3' : printPoints( locations3, 3 ); break;
            default : printf( "\nNOT implemented here yet ... \n" );
        }
        putchar( '\n' ) ;
    }
    while( more() ) ;

    return 0;
}
David W 131 Practically a Posting Shark

I just remembered this link re. Newton's Method of Finding Roots ...

Newton's Method of Finding Roots

David W 131 Practically a Posting Shark

So ...

if you want the count of the numbers at the end ...

(as per your example output)...

after you have tallied up all elements in your array ...

you could use 3 loops for the printout:

int i;

for( i = 'A'; i <= 'Z'; ++ i )
{
     if( ary[i] ) /* if NOT zero ... */
         printf( "%c = %d\n", i, ary[i] );
}
for( i = 'a'; i <= 'z'; ++ i )
{
     if( ary[i] ) /* if NOT zero ... */
         printf( "%c = %d\n", i, ary[i] );
}
for( i = '0'; i <= '9'; ++ i )
{
     if( ary[i] ) /* if NOT zero ... */
         printf( "%c = %d\n", i, ary[i] );
}
David W 131 Practically a Posting Shark

Your questions are not really clear ...

If you need different sized arrays ... you could use dynamic allocation of memory

or just use two defines

#define SIZE_10 10
#define SIZE_20 20
// etc

re. the 2nd question ...
you can use

if( condition1IsTrue ) { /* */; )
else if( condition2IsTrue ) { /* */; )
// ...
else { /* */; )

or ...

switch( intVal )
{
case val1: /* */; break;
case val2:  /* */; break;
// 
default:  /* */;
}
David W 131 Practically a Posting Shark

Just looked your problem over ...

This may get you started ...

//5 courses available

//only 8 allowed in each course 
//(so ... in main ... need 5 queue, each of size 8)
// perhaps an array of StudAryQue
// StudAryQue mySchool[5]; // holds all ...
// or ...
// StudAryQue course1, course2, course3, course4, course5;

//first come first served
//a queue is a 'first in first out' 
//(FIFO) data conainer

//a student can choose up to 5 max 
//(different available) courses


/*
0 1 2 3 4 5 6 7 
- - - - - - - -

^
|
first student ...
  ^
  |
  2nd student ...
*/

then ...

const size_t MAX_NUM = 8;

struct Student
{
    // your data, etc go here ...
    string id;
    string course;
} ;

struct StudAryQue
{
    Student que[MAX_NUM];
    int pos;

    StudAryQue() : pos(-1) {}

    size_t size() const { return pos+1; }
    bool isFull() const { return MAX_NUM == size(); }

    void push( const Student& s ) 
    { 
        if( !isFull() ) que[++pos] = s; 
        //else // print some error message ?
    }

    Student front() const
    {
        if( size() ) // if not empty
            return que[0];
        // else ...
        return Student(); // empty Student
    }

    void pop()
    {
        if( size() ) // if not empty
        {
            // your code for pop goes here
        }
    }

    // anything else you may need ...
} ;
David W 131 Practically a Posting Shark

What do you already know about a 4th power poly... ?

Can you (differentiate and) find the max (extreme points -> if the graph of y = ax^4 + bx^3 + cx^2 +dx + e opens down) ... or min ... if it opens up ?

From the extreme points ... and it it opens up or down ... can you see if it (touches or) crosses the x-axis ( ... so will have (1 or more) real roots then ... the rest imaginary <--always in pairs ,,,

niteshkumar.singh.9083 commented: YES i can +0
David W 131 Practically a Posting Shark

Recalling the above good insights of @Ancient Dragon ...

I would do it by using an array of 255 ints, each element in the array represents one of the characters in standard ascii character set. So, if you enter 'A', then all you have to do is increment array['A']++. When done, all the non-zero elements are what you want. Now, you know that many of the 255 elements will be unused, so you can limit the array to only 126 or fewer. If the array has 126 elements (values above 126 can not be entered on the standard English keyboard).

Just in case you do not 'see' what is 'implicitly needed' in that approach ...

// MUST firstly initial all elements to 0

int ary[128] = { 0 }; // initial all to zero ...

// then traverse all char's 'c' ...
// and update ...
if( (c >= 'A' && c << 'Z') || (c >= 'a' && c << 'z')
|| (c >= '0' && c << '9') )
++ ary[c];

David W 131 Practically a Posting Shark

But ... what if the OP is using his real name ... and is just beginning coding ?

David W 131 Practically a Posting Shark

You need to turn them on, on your compiler ... to see them.

#include <windows.h>

//#include <stdio.h> // C usage style
#include <cstdio>    // C++ usage style

//#include <string.h>
include <cstring>

#include <cstdlib>
#include <ctime>

//#include <ctype.h>
#include <cctype>


#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

using namespace std;
David W 131 Practically a Posting Shark

You have several compile errors ...

In line 81:

ISO C++ forbids variable length array 'boardWithPieces'

You could use a ...

vector < string > vecStr( size ); // calls constructor
// if you really need an 'array of strings'

You also have redundant and several C (not C++ type includes)

David W 131 Practically a Posting Shark

The coding problem that you seem to be posing is not a 'beginner type' problem, I would say ... So you should be able to post some code ... other wise ... the problem needs to be put off until you have some more coding skills.

And ... the coding spec's you give are not well defined ... Is your problem to simulate file storage ... but to use RAM and an array as the storage unit to access RAM?

David W 131 Practically a Posting Shark

Show your complete new code.

David W 131 Practically a Posting Shark

Ok ... post the code you have so far ... and where you think you are having a problem.

David W 131 Practically a Posting Shark

But ...

C doesn't allow overloaded functions.

David W 131 Practically a Posting Shark

Python lends itself to jumping right in and start coding...

This example code below may give you some ideas about how to get started ...

# selectRobot.py #  # 2014-03-26 #

'''
The output will be like below:

    what type of robot application you like choose?
    a) assembly
    b) spot welding

Then let say the customer choose a or b, it will go to next question:

2.How much the load you expect for the robot to carry?
a) 0-2 kg
b) 0-5 kg

And so on ...

This is just a start ... need to continue ...
until finished choosing all attributes of the desired robot.

'''

menu1 = \
'''Please choose the type of robot application ?
    a) assembly
    b) spot welding
Please enter a or b    :  '''

menu2 = \
'''What is the max load for this robot?
    a) 0-5   kg
    b) 6-10  kg
    c) 11-15 kg
Please enter a, b or c :  '''

menu3 = \
'''What is the reach for this robot?
    a) 0-1 m
    b) 1-2 m
Please enter a or b    :  '''

menu4 = \
'''What is the mounting for this robot?
    a) floor
    b) wall
Please enter a or b    :  '''

def showMenuGetChoice( menu, low, high ):
    while True:
        reply = input( menu ).lower()
        if low <= reply and reply <= high:
            return reply
        else:
            print( "'", reply, "' was NOT in valid " \
                   'input range ', low, '..', high, sep = '' )

modelsStr = [] …
David W 131 Practically a Posting Shark

You may like to see a version that uses dynamic memory...

/*matrixStructMult2.c */

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

typedef int myType;

typedef struct twoDArray
{
    myType **data;
    int rows;
    int cols;
} Matrix ;


/*
   The 'struct' holds a 'pointer to a pointer to int' for the 2-D array ...  
   AND ALSO holds the number of rows and cols for the 2-D array.
*/
void createMatrix( Matrix*, int, int );
void showMatrix( const Matrix* );
void freeMatrix( Matrix* );



int main()
{
    int i, j, k;
    int r = 2, c = 3;
    int count = r*c*2;
    int sum = 0;
    Matrix M1, M2, M3;

    createMatrix( &M1, r, c );

    /* fill in some values ... */
    for( i = 0; i < M1.rows; ++i )
        for( j  =0; j < M1.cols; ++j )
            M1.data[ i ][ j ] = count--;

    createMatrix( &M2, c, r+2 );

    /* fill in some values ... */
    for( i = 0; i < M2.rows; ++ i )
        for( j = 0; j < M2.cols; ++j )
            M2.data[ i ][ j ] = count--;

    createMatrix( &M3, r, r+2 );


    /* product first two matrices ...*/

    for( i = 0; i < M1.rows; ++i )
        for( j = 0; j < M2.cols; ++j )
        {
            for( k = 0; k < M2.rows; ++k )
            {
                sum += M1.data[i][k]*M2.data[k][j];
            }
            M3.data[i][j] = sum;
            sum = 0;
        }


    puts( "\nMatrix1" );
    showMatrix( &M1 );

    puts( "\nx Matrix2" );
    showMatrix( &M2 );

    puts( "\n= Matrix3" );
    showMatrix( …
David W 131 Practically a Posting Shark

You may like to take a look at this ...

// getPassWord.cpp //

#include <iostream>

using namespace std;

// passing in by 'ref' so value in calling scope is updated //
void getPassWord( string& password )
{
    cout << "Enter your pass word: " << flush;
    getline( cin, password );
}


int main()
{
    int count = 3;
    string password;
    while( count )
    {
        getPassWord( password );
        if( password == "pass" ) break;

        // else ... if reach here ...
         --count;
        if( count )
        {
            cout << "Wrong password ... try again ...\n"
                 << "You have " << count << " more tr"
                 << (count > 1 ? "ies.\n" : "y.\n" ) ;
        }
    }

    if( count ) cout << "\nYeh ... you got in ... \n";
    else cout << "\nYou are an intruder ... "
              << "NO access here for you today!\n";
}
David W 131 Practically a Posting Shark

Oops again :(
Please see below ...

David W 131 Practically a Posting Shark

Oops ... see below please ...

David W 131 Practically a Posting Shark

Hey ... in Assembly Language, the structures we use in 'structured programming' ... are all built up from jumps / goto's ... no worries :)

And ... variety is nice ... but so is clear, clean logic flow :)

David W 131 Practically a Posting Shark

Because maybe he need to show example of goto statement, I don't care about reasons. Problem is solved and that's all I care about.

@Kristian_2
You do know that there is much more to coding, than ...

Problem is solved and that's all I care about.

Program (logic) flow ... using a standard structured coding style ... will make your code MUCH easier for you ... or some-else ... to maintain.

Some (complex) error handling may sometimes yield simpler code using a goto ... otherwise best to stick with 'best practice' usage of (a) standard coding style.

David W 131 Practically a Posting Shark

You seem to be making an easy thing hard ...

See this example of reading a 2D matrix from file, printing it back and then searching it to find a point ...

// myMatrixSearch.cpp //

/*

2 5
1 2 3 4 5
6 7 8 9 0

with the leading 2, indicating the number of rows
with the next 5, indicating the number of col's

you could read this into a matrix like this (using the STL vector container) ...

*/

const char* FNAME = "matrixData.txt";

#include <iostream>
#include <iomanip> // re. setw( )
#include <fstream>
#include <vector>

using namespace std;

ostream& operator << ( ostream& os, const vector< vector < int > >& v )
{
    for( size_t i = 0; i < v.size(); ++ i )
    {
        for( size_t j = 0; j < v[i].size(); ++ j )
        {
            os << ' ' << setw(8) << v[i][j];
        }
        os << endl;
    }
    return os;
}

struct Point
{
    int x, y;
    Point() :  x(-1), y(-1) {} // NOT found value
    Point( int a, int b ) :  x(a), y(b) {}
    void print() const
    {
        cout << x << ", " << y;
    }
} ;

Point find( const vector< vector < int > >& v, int val )
{
    for( size_t i = 0; i < v.size(); ++ i )
    {
        for( size_t j = 0; j < v[i].size(); ++ j )
        {
            if( val == v[i][j] ) return Point( i, j );
        }
    }
    // …
David W 131 Practically a Posting Shark

hint_prompt = hint_prompt.lower()

the string is converted to all lower case

David W 131 Practically a Posting Shark

Or ... start bottom up ... and code in small steps ... making sure that it 'works' as expected, (gives exact desired output), at each step ... and that YOU UNDERSTAND EACH step!

There is no shortage of example code ... re. matrix multiplication ... on the web ... if you do a little search ... even here at Dani... lots!

David W 131 Practically a Posting Shark

Sometimes ... the obvious ... is alarmingly simple ... when you 'see' it :)

C arrays start at index 0, so next in, from front, has index 1,

and ... the last index is size-1 (if size > 0 ),

so next to last index is size-2 (if size > 1)

David W 131 Practically a Posting Shark

Show the code you have ... and where you think you are stuck ...

David W 131 Practically a Posting Shark

Show the code you have ... and where you think you are stuck ...

David W 131 Practically a Posting Shark

Hey ... start a new thread please ... did you not see that one was 5 years OLD ?

int main() // not void main in standard C
{
    // your code ...
    return 0; // main returns an int in standard C
}
David W 131 Practically a Posting Shark

Show us the code you have so far ... are where you think you are stuck.

Here is a student beginner level example of using functions to validate user input ...

// getValidInt.cpp

// http://developers-heaven.net/forum/index.php/topic,46.0.html

#include <iostream>
using namespace std;

int getValidInt( const char prompt[] )
{
    for( ; ; ) // an example of a C/C++ forever loop ... until 'return'
    {
        cout << prompt << flush;
        int testInt;
        cin >> testInt;
        if( cin.good() )
        {
            cin.sync(); // 'flush' cin stream as we go ...
            return testInt;
        }
        // else ...
        cin.clear(); // clear cin error flag(s) ...
        cin.sync();
        cout << "Invalid input! Integers only please ...\n" ;
    }
}

bool more()// defaults to 'true'/'yes' ... unless 'n' or 'N' entered
{
    cout << "More (y/n) ? " << flush;
    int reply = cin.get();
    cin.sync(); // 'flush' cin stream ...
    if( reply == 'n' || reply == 'N' ) return false;
    // else ...
    return true;
}


int main()
{
    int count = 0, sum = 0;

    do
    {
        int testInt = getValidInt( "Enter next integer to sum: " );
        sum += testInt;
        ++count;
    }
    while( more() ); // make sure cin stream is 'empty' before calling more()

    cout << "\nFor " << count << " numbers entered, sum was " << sum
         << " and average was " << float(sum)/count << endl;

    cout << "\nPress 'Enter' to continue/exit ... " << flush;
    cin.get(); // keep 'Window' open until 'Enter' key is pressed ...
}
David W 131 Practically a Posting Shark

Do you 'see' the output here ... yes it prints '64' !

 cout << "\nThe following (new array_list) "
      << "is not from file\n\n";
SortedList x;
cout << "Inserting 64 ... ";
x.insert(64);
cout << "\nx.print(cout)... \n";
x.print( cout ); /// *** what does this do ? *** ///
cout << "\nx.size() = " << x.size();
cout << "\nErasing 64 ....";
x.erase(64);
cout << "\nx.print(cout)... \n";
x.print( cout );
cout << "\nx.size() = " << x.size();

But ... one should have really inserted several values and erased several values ... printing the list at each insert and erase ... to better check to see if the code is correct ... i.e. output was ... as desired ?

Try this:

cout << "\nThe following (new array_list) is not from file\n\n";

   SortedList x;
   cout << "Inserting 64 74 70 60... ";
   x.insert(64);
   x.insert(74);
   x.insert(70);
   x.insert(60);
   cout << "\nx.print(cout)... \n";
   x.print( cout );
   cout << "\nx.size() = " << x.size();

   cout << "\nErasing 64 ....";
   x.erase(64);
   cout << "\nx.print(cout)... \n";
   x.print( cout );
   cout << "\nx.size() = " << x.size();

   return 0;
David W 131 Practically a Posting Shark

Show the code you have so far ... and where you think you get stuck.

David W 131 Practically a Posting Shark

You need to show the code you have so far ... and where you are stuck.

David W 131 Practically a Posting Shark

You need to show the code you have so far ... and let us know where you are stuck.

David W 131 Practically a Posting Shark

Using several functions ... a function for each task ...

could really help your program development ...

and help elucidate the logic flow.

// restaurant.cpp //


#include <iostream>
#include <string>

// to keep code portable ... best not to use this //
#include <windows.h> 


using namespace std;


const string HEADER = "TAPSI NI VIVIAN'S MENU";

struct Item
{
    string name;
    double price;
} ;

// putting data here, in an array of struct ... 
// makes your program more generic
// i.e. easier to revise ...
const Item MENU[] =
{
    { "Tapsilog", 80.00 }, { "Longsilog", 95.00 },
    { "Bulalo", 225.00 }, { "Sisig with Egg", 140.00 },
    { "Beef Mami", 50.00 }, { "Bottled Softdrinks", 25.00 },
    { "Canned Softdrink", 25.00 }, { "Minute Maid", 30.00 },
    { "Nestea", 20.00 }, { "Bottled watter", 15.00 }
} ;

const int NUM_CHOICES = sizeof MENU / sizeof *MENU;

// to keep code portable ... best not to use this //
void gotoxy(short x, short y)
{
    COORD pos = {x, y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

void printMsgAt( const Item& itm, short x, short y )
{
    gotoxy( x, y );
    cout << itm.name << " P" << itm.price;
}

double getOrder( string& name )
{
    string msg, line( 65, '-' ); // construct string 65 '-'

    double amount = 0;
    for( ; ; ) // loop forvever until ... break or return ...
    {
        gotoxy( (60-HEADER.size())/2, 0 );
        cout << HEADER;

        short i;
        for( i = 0; i < …
Ancient Dragon commented: excellent advice +14
David W 131 Practically a Posting Shark

Since you are using C++, why not use C++ string (not C string)

And don't use (risky) gets ... (even in C)
In C++ with C++ string

#include <string>

then can code

string cppStr;
cin >> cppStr';
// or ...
getline( cin, cppStr );

Also !

it is ...

int main() // main returns an int
{
   // your code
   return 0;
}

Also ...

// else; // NOT what you want //
else
{ // need this ...
    cout<<"Want to add an another order? (Y or N): ";
    cin>>again;
    cout<<"\n";
} // need { ... } to include the whole 'else' block

Need other fixes ... this is a start :)

David W 131 Practically a Posting Shark

Perhaps your design spec's...

really does want you to copy each user input to a file
(append to a file) ...

right away after each line has been input?

The example 'dialog', you provided, does 'lend itself' to that simple interpretation ... yes/no ?

If that is what was 'expected',

this example may help:

# projectReadWriteNotebook2.py #

'''
    ... the other continuous project, the notebook, has relied on user actions 
    in the sense that it would have broken down if the user had decided to read
    the file without writing anything to it. In this exercise we fix this, and
    add the possiblity of changing the used notebook file while the program is 
    running.

    First of all, make the program start by checking if there is a file 
    "notebook.txt" and create one if there is none. If this has to be done, 
    also inform the user with the warning "No default notebook was found, 
    created one.".

    When this feature works, add a fourth selection to the notebook, 
    "(4) Change the notebook". If the user selects this option, 
    the user is prompted for a new file 
    "Give the name of the new file: ". 
    If there is an existing file, it is opened and loaded into the notebook 
    program, while the old notebook file is closed. If the new notebook file 
    does not exist, the system informs the user 
    "No notebook with that name detected, created one." 
    and makes a new file. Also add a note of the used …
David W 131 Practically a Posting Shark

This example may give you some ideas how your above code could be re-coded using C++ idioms (and not Java idioms) ...

// insertSortedAryList.cpp //

#include <iostream>
#include <fstream>
//#include <string>

using namespace std;


#define show 0 //set to 1 to turn ON 'showing...'//

const int MAX_ITEMS = 100; // need = at least 13 here ... //
const char* FNAME = "float.txt";
const char* FNAME_OUT = "float_sorted.txt";
/*
10.3 11.2 12.7 0.8 -3.2 11.7 -22.9 -1.1 9.9 -111.1 999 -999 0
*/


typedef float ItemType;
typedef ItemType* iter;
typedef const ItemType* const_iter;

class SortedList
{
public:

    SortedList() : length(0) {}

    int size() const  { return length; }

    void clear() { length = 0; }

    bool insert( const ItemType& x )
    {
        //cout << "length = " << length << endl;
        int i = 0;
        if( length < MAX_ITEMS )
        {
            if( length )
            {
                i = findInsertIndexBinSearch( x );
                if( i < length )
                {
                    // open up hole at index i
                    for( int hole = length; hole > i; --hole )
                    values[hole] = values[hole-1];
                }
            }
            values[i] = x;
        }
        else
        {
            cout << "\nList was FULL! NO room to insert!\n";
            return false;
        }
#if show
        cout << " at index[" << i << ']' << endl;
#endif
        ++length;
        return true;
    }

    bool erase( const ItemType& x )
    {
        bool wasDeleted = false;
        int i = foundAtIndexBinSearch( x );
        if( i >= 0 )
        {
            // copy down over item at index index i
            for( int j …
David W 131 Practically a Posting Shark

It is never recommended to use the input with evaluation.

Are you above talking about Python 3?

I would change that to ...

It is robust coding style that always checks for valid input... perhaps, for example, using exception handling to deal with errant alpha input when numeric was expected.

So I allways use the raw_input only.

Are you saying that you never use ...
num = input( msg )
with exception handling, in Python 2.x?

And I use overwriting of evaluating input function to ensure that code does not have dangerous input statements

Perhaps you could give example(s) for the above ... so it is clear what you mean?

David W 131 Practically a Posting Shark

Ok ... but then ... in Python 2.x...

num = input( msg ) # always? returns a string
                   # and your 2.x... code may have ...
                   # been expecting a number ?

                   # So ... don't you then ... have to
                   # fix-up all those inputs ... ?
David W 131 Practically a Posting Shark

Once you get started coding in Python ... and get some feel for its (often very) simple coding style and power ... you may then want to DO many of your programming jobs in Python first ... and many of those, then ... may never get recoded in C++ :)

Here is a little demo C++

struct 'Contact' ...

with a way one might recode it in Python 3

that may help get you past 'go' ...

Firstly the C++ code ...

// Cpp_vs_Python.cpp //

#include <iostream>
#include <string>

using namespace std;

struct Contact
{
    string name;
    string phone;

    string toString() const
    {
        return name + ", " + phone;
    }
} ;


typedef Contact* iter;

int main()
{
    Contact book[] = { {"Sam", "1234567890"},
                       {"Bill", "2345678901"} };

    iter it,
         begin = book,
         end = book + (sizeof book / sizeof *book) ;

    cout << "Showing contacts in book ...\n";
    for( it = begin; it != end; ++it )
         cout << it->toString() << endl;

    cout << "Press 'Enter' to continue/exit ... " << flush;
    string dummy;
    getline( cin, dummy );
}

Ok ... now here is how one might recode this in Python 3
(Note how much shorter and simpler is the Python code.)

# Cpp_vs_Python.py #

class Contact:
    def __init__(self, name, phone):
        self.name = name
        self.phone = phone
    def __str__(self):
        return self.name + ', ' + self.phone

# get some data into a book (a list of Contact)

book = [ Contact("Sam", "1234567890"), Contact("Bill", "2345678901") …
David W 131 Practically a Posting Shark

@pyTony: Can one still use raw_input in Python 3 ?

David W 131 Practically a Posting Shark

You could try something like this ...
(that uses the code given you by @Gribouillis ... slightly revised ... and with comments added that may help explain it for you.)

filename = 'myData.txt'
'''
07 13 14 23 45 - 04
13 27 34 41 47 - 49
22 24 45 46 51 - 15
10 14 22 23 42 - 13
01 04 17 31 52 - 38
12 23 40 47 57 - 04
'''

def score(i, t): # i = items_set, t =target_set
    # returns number of items in intersection set of target & item sets
    # also returns True or False indicating if the last items match
    return ( len( set(i[:5]) & set(t[:5]) ), i[-1] == t[-1] )

import fileinput as fin

text1 = '(Number of Items in Intersection,'
text2 = ' Last Items do Match?)'
stars = [ ' *' for i in range(5) ] + [ '-', ' *']

i = 0
for line in fin.input( filename ):
    items = line.split()
    if i == 0:
        target = items
        print( 'Target' )
        print( items )
        print( '\nItems', ' '*4, text1, text2  )
        print( stars, ' *, ***** ' )
    else:
        print( items, score(items, target) )
    i += 1

input()
David W 131 Practically a Posting Shark

Maybe ...

You could 'wrap' the 'flag' variables in their own namespace ...

namespace MyFlags
{
    bool from_User = false;
    bool to_Screen = true;
    bool update_Changes = false;
}
David W 131 Practically a Posting Shark

Oops above link is dead, try this:

example bubble sort with function pointers

David W 131 Practically a Posting Shark

Ok ...

I would recommend a few revisions ...

If you were to use function pointers, (for the compare functions in your 3 different bubble sorts), you could vastly reduce and re-use the bubble sort code.

    void City_list::sortBy( bool (*cmp) (const City& a, const City& b) )
    {
        bubble_sort( cmp );
    }

Take a look ...

typedef vector < City > ::const_iterator const_iter;
typedef vector < City > ::iterator iter;

class City_list
{
public:

    City_list() : myCities() {}

    void takeInCity(istream& is)
    {
        City c;
        c.takeIn_p(is);
        c.takeIn_city_name(is);
        myCities.push_back(c);
    }

    void showDistance() const
    {
        City a, b;
        From_User = true;
        a.takeIn_city_name(cin);
        const_iter it, ita, itb;
        ita = myCities.end();
        for (it = myCities.begin(); it != myCities.end(); ++it)
        {
            if (it->get_city_name() == a.get_city_name())
            {
                ita = it;
            }
        }

        if (ita == myCities.end())
        {
            cout << a.get_city_name() << " NOT found.\n";
            return;
        }

        b.takeIn_city_name(cin);
        itb = myCities.end();

        for (it = myCities.begin(); it != myCities.end(); ++it)
        {
            if (it->get_city_name() == b.get_city_name())
            {
                itb = it;
            }
        }

        if (itb == myCities.end())
        {
            cout << b.get_city_name() << " NOT found.\n";
            return;
        }

        cout << "\nThe distance from " << a.get_city_name() 
             << " to " << b.get_city_name() 
             << " is " << ita->distance(*itb) 
             << endl << endl;
    }


    void print() const
    {
        cout << "\nAll cites listed:\n";
        const_iter it; // using typedef //
        for (it = myCities.begin(); it != myCities.end(); ++it)
            cout << *it << endl;
    }

    void sort()
    {
        switch ( takeInChar("Sort on 1. Name, 2. X 3. Y :  ") ) …
David W 131 Practically a Posting Shark

You could use functions to take in (and prompt and validate) all user input ... this would make your code more robust and modular.

For example, to prompt and to loop until the user has input a valid double ...

double takeInDbl( const char* msg )
{
    double val;
    while( true )
    {
        cout << msg << flush;
        if( cin >> val && cin.get() == '\n' )
            break;
        else
        {
            cout << "Invalid input ... numbers only!\n";
            cin.clear(); // clear error flasgs
            cin.sync(); // 'flush' cin stream ...
        }
    }
    return val;
}


// ... then later ...

// prompt and loop until valid double was input
double rate = takeInDbl( "PLease input rate: " );

// rest of code ...
David W 131 Practically a Posting Shark

If you wanted to take in really long numbers ...

you could use a large char buffer

char buffer[256];

to take in the chars using fgets

Then easy to travese that buffer and extract pairs of numbers into an array of pairs

int pairs[100];

then process that array of integers

David W 131 Practically a Posting Shark

Very creative ... :)

-> using pre-fixed length C strings ... (Not a good idea usually...in designing a C++ string class ?)

-> some curious stuff ... that I am surprized that you even got compiled and then to have any good output ?

BUT ... please turn on your COMPILER error warnings ... so you can see what to fix ... and then ... look at the example below ... and see all the embedded comments ... to see the way a typical student class String ... is (normally) expected to look ...

// student_classString.cpp //

/*
    okay,. so far am to this point,. 
    i have managed to do a version of strcat which include a 
    array and a pointer,. 
    but i still have problems with the other function..
*/

/*
    Ok ... you seem to be needing a little nudge in the
    'right direction' ... to get started
    please lookup or Google 'the big 3 of C++ classes' ... 
*/


#include <iostream>
#include <cstring> // re. strlen

using namespace std;


class MyString
{
public:
    MyString();
    ~MyString(); // 1... of 'BIG THREE' ... needed here

    // copy ctro...
    MyString( const MyString& ); // 2... of 'BIG THREE' ...

    // ALSO, need to have ...
    // ctor from passed in C string ... 
    // (so can construct fron C strings)
    MyString( const char[] );

    // overloaded assignment ...
    MyString& operator = ( const MyString& ); // 3... of 'BIG THREE' ...

    MyString& concat( const char[] );
    MyString& concat( const …
David W 131 Practically a Posting Shark

Ok ...

still not clear what you are trying to do ...

suppose you have lines in a big file that look like this:

sxxxxxxxxxxxxxx...
rxxxxxxxxxxxxx...
rxxxxxxxxxxxxxx....
sxxxxxxxxxx............
sxxxxxxxxxxxxxx............
r............

to 100,000,000 + lines

ok ... suppose you are taking 2 successive samples for the intervals of 0.001 seconds each

you could read in all the lines into a list of lines ...for 0.002 secs ....

then process that list ... 1st half & 2nd half