Menu

How do I define an apvector (1-D array)?

2010-01-31
2012-09-26
  • TinyandTall

    TinyandTall - 2010-01-31

    Sorry this sounds so lame to be asking, but I just got this program and
    switched from an ancient program and this program hardly likes anything I try
    to type into it soooo I am just starting from the beginning...

    Do you know how to define an array?

     
  • TinyandTall

    TinyandTall - 2010-01-31

    include <iostream>

    include <apvector>

    using namespace std;

    int main (int argc, char *argv)
    {
    char quit;
    int I;
    apvector (Numb) int <4>;
    I=0;
    quit = '\0';
    while (quit!='q')
    {
    for(I=0;I<4;I++)
    {
    cout<<"Please enter 4 numbers";
    cin>>Numb_;
    cout<<"First";
    gotoxy(1,5);
    cout<<
    }
    cout<<"enter q to quit";
    cin>>quit;
    }
    return 0;
    }

    that is my code so far... I just need to get the vector working and then I can
    probably go from there (and I'm pretty sure the code gotoxy( , ) may not work
    in this program but I figured I would try it)_

     
  • cpns

    cpns - 2010-01-31

    Use code tags mark-up when posting code.

    I am guessing that you took the Advanced Placement Computer
    Science

    course in the US between 1999 and 2003. Either that or a course based on their
    'simplified' libraries. Unfortunately there are still courses that appear to
    be using them! We used to get questions about this here regularly; you are the
    first for some time!

    The AP CompSci course ill-advisedly introduced 'simplified' non-standard class
    libraries for teaching purposes. Unfortunately they did not seem to emphasise
    the fact that they were proprietary classes for teaching principles, and are
    not generally available in _any _ compiler; they were provided as course
    specific material.

    There is probably nothing different about this compiler that is causing your
    problem; libraries are distinct from the compiler itself. That said I am not
    sure that your syntax for declaring Numb is valid in any compiler. You have
    two choices; 1) track down an implementation of the AP C++ libraries (not
    recommended), 2) Learn to use the standard C++ libraries.

    I am not sure why the programme felt the need to 'simplify' these libraries
    rather than just teach a subset of the standard ones. Their programme may have
    produced a few_ Computer Scientists_, but it has stunted the growth and
    discouraged a number of Software Developers! They are probably still doing
    so using Java now!

    Documentation for the the standard equivalents to the AP libraries can be
    found for example here or
    here.

    One other problem is that the function gotoxy() is not a standard function.
    Standard C/C++ libraries are intended to be implementatble on almost any
    platform, so assume lowest common denominator functionality, and that is the
    functionality of a "Dumb
    Terminal"
    . The
    Windows Console API has means to do this, but it is a little
    more complex. A clone of Borland's DOS conio library that includes gotoxy() is
    available here, but it is
    probably better to wean yourself of this crutch just as it is the AP library.

    The line following the gotoxy() call is incomplete (in any compiler). I guess
    this code is yet incomplete.

    The following compiles; I have marked-up the lines that needed
    modifying/adding. It does not however seem to do any thing sensible, but I'll
    leave you to fix that or open another question. I guess when you have
    completed it it will work.

    #include <windows.h>
    #include <iostream>
    #include <vector>   ///////////////////////////////////
    
    using namespace std;
    
    ///// ----START----/////
    void gotoxy(int x, int y);
    ///// ----END----/////
    
    int main (int argc, char *argv[])
    { 
        char quit;
        int I;
        vector<int> Numb( 4 ) ;  /////////////////////////////// 
        I=0;
        quit = '\0';
        while (quit!='q')
        {
            for(I=0;I<4;I++)
            {
                cout<<"Please enter 4 numbers";
                cin>>Numb[I];
                cout<<"First";
                gotoxy(1,5);
                ////////////////// cout<<
            }
            cout<<"enter q to quit";
            cin>>quit;
        }
        return 0;
    }
    
    ///// ----START----/////
    void gotoxy(int x, int y)
    {
        HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE) ;
        COORD coord = {x - 1, y - 1} ;
        SetConsoleCursorPosition( console, coord );
    }
    ///// ----END----/////
    
     
  • cpns

    cpns - 2010-01-31

    Note how the use of code mark-up prevented the forum from turning the index to
    the Numb array into itallics markup!

     
  • TinyandTall

    TinyandTall - 2010-01-31

    Well the program does like the way I have been taught to code and I am
    currently in and AP computer science class.... I am a brand new coder, but I
    found the program that we use in that class so I am okay now. But thanks
    anways.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.