Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    0
    ReputationRep:
    A levels Computing (9691) paper 2 has questions which requires statement which declares an array. For example "Some one needs to store title an authors of books in an array. He expects to have 200 books; A two dimensional array is to be used; In a high level language write an array declaration statement" I face some problems with this questions as i use c++ language and need an array of char for string data. so my statement becomes char Books[50][200][200] the first dimension gives the maximum size of each data. Thus it actually becomes a three dimesional array. Is it acceptable answer to the question asked? Or is it acceptable to use string class of c++?
    Offline

    3
    ReputationRep:
    I'm positive that you can use the string class... c++ is not my language, though.
    Offline

    3
    ReputationRep:
    std::string Books[x] [y] ;

    would work using the string class.

    Posted from TSR Mobile
    Offline

    3
    ReputationRep:
    (Original post by SkyJP)
    std::string Books[x] [y] ;

    would work using the string class.
    ...
    You seem to know what you're talking about, so I'll ask you! :-p
    Take the above question, but say there's just 3 books & 3 authors;
    How would that be written?
    I understand- char arrayname[x] [y]; defining it as a 2 dimensional array, but how would you separate the author from the titles? Also, for eg, use A1, A2, A3 & T1, T2, T3? I don't know C++ but want to absorb as much as possible :-)
    Guessing;
    char titleauthor[3] [2]; some sort of {A1, A2... ("A1", "A2, "A3")("T1", "T2"... ?
    :-)






    PlGLET
    • Thread Starter
    Offline

    0
    ReputationRep:
    For starters you declare a three dimensional array with char or use a std::string
    char array_name[max_length][max_title][max_author]
    or
    std::string array_name[max_title][max_author]
    working with strings each book's author is given by position corresponding to title for example
    array_name [i][1] would give author for book stored in position
    array_name[i][0]
    its the basic concept of array programming although a beeter method would be to use structures or maybe even classes

    (Original post by PlGLET)
    You seem to know what you're talking about, so I'll ask you! :-p
    Take the above question, but say there's just 3 books & 3 authors;
    How would that be written?
    I understand- char arrayname[x] [y]; defining it as a 2 dimensional array, but how would you separate the author from the titles? Also, for eg, use A1, A2, A3 & T1, T2, T3? I don't know C++ but want to absorb as much as possible :-)
    Guessing;
    char titleauthor[3] [2]; some sort of {A1, A2... ("A1", "A2, "A3"("T1", "T2"... ?
    :-)






    PlGLET
    Offline

    3
    ReputationRep:
    (Original post by sambid)
    A levels Computing (9691) paper 2 has questions which requires statement which declares an array. For example "Some one needs to store title an authors of books in an array. He expects to have 200 books; A two dimensional array is to be used; In a high level language write an array declaration statement" I face some problems with this questions as i use c++ language and need an array of char for string data. so my statement becomes char Books[50][200][200] the first dimension gives the maximum size of each data. Thus it actually becomes a three dimesional array. Is it acceptable answer to the question asked? Or is it acceptable to use string class of c++?
    Why use C++? It asks for a high level language. And no, I'm not sure that's ok, after all, as you say, it becomes a 3d array.

    I know courses seem to like python, but I don't know python, so I'll do it in ruby:

    books = [[], []]

    So much simpler.

    Try codecademy if you want to learn enough of something like ruby to tackle these kinds of questions. You should be able to get through it all in a day.
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Has a teacher ever helped you cheat?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Write a reply...
    Reply
    Hide
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.