The Student Room Group

Answering A levels Computing Programming questions with c++

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++?
(edited 8 years ago)
I'm positive that you can use the string class... c++ is not my language, though.
Reply 2
std::string Books[x] [y] ;

would work using the string class.

Posted from TSR Mobile
Reply 3
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
Reply 4
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 [1] would give author for book stored in position
array_name[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":wink:("T1", "T2"... ?
:-)






PlGLET
Reply 5
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.
(edited 7 years ago)

Quick Reply

Latest

Trending

Trending