• What do you need help with? Version 1
    5,001 replies, posted
I need to split a huge text file: [url]http://www.gutenberg.org/dirs/etext04/grimm10a.txt[/url] Into 200 smaller text files with a certain formatting, with the title of each story being the filename, and the contents being the story. What would be well suited to do this automatically?
You already know any programming language?
Got only 3 questions this time,and 1 I already think I know the answer too :) [QUOTE]An accessor function of a class first accesses the values of a member variable of the class and then changes the values of the member variable. A) True B) False [/QUOTE] Not sure on this one [QUOTE]class secretType { public: static int count; static int z; secretType(); secretType(int a); void print(); static void incrementY(); private: int x; static int y; }; secretType::secretType() { x = 1; } secretType::secretType(int a) { x = a; } void secretType::print() { cout << "x = " << x << ", y = " << y << "z = " << z << ", count = " << count << endl; } static void secretType::incrementY() { y++; } Consider the accompanying class and member functions definitions. How many constructors are present in the class definition above? A) 0 B) 1 C) 2 D) 3 [/QUOTE] This is c right? [QUOTE]class secretType { public: static int count; static int z; secretType(); secretType(int a); void print(); static void incrementY(); private: int x; static int y; }; secretType::secretType() { x = 1; } secretType::secretType(int a) { x = a; } void secretType::print() { cout << "x = " << x << ", y = " << y << "z = " << z << ", count = " << count << endl; } static void secretType::incrementY() { y++; } Consider the accompanying class and member functions definitions. Which of the following statements correctly creates the object mySecret of type secretType and sets the value of the member variable x to 9? A) secretType mySecret(9); B) mySecret = secretType(9); C) secretType = mySecret(9); D) secretType(9).mySecret; [/QUOTE] not sure on this one either
[QUOTE=shemer77;23369753]Got only 3 questions this time,and 1 I already think I know the answer too :) Not sure on this one This is c right? not sure on this one either[/QUOTE] neither are c, and use [noparse][cpp]code[/cpp][/noparse] for code
1.) I THINK is false, not 100% sure -> I think it's false because an "Accessor", as the name suggests, provides access to a member variable. Now, I'm not entirely sure, but I think it just means you can get the value of the variable, rather than changing it. 2.) Is C (Assuming that two constructors for the same class still counts as 2) -> The SecretType class has two constructors: [cpp]secretType(); secretType(int a);[/cpp] Any function inside a class with the same name as the class and no return type is a constructor. 3.) Is A -> The "secretType(int a)" constructor sets the value of X to whatever was passed as a. Therefore to create an instance of the class, and set X to 9 you would use option A: [cpp]secretType mySecret(9);[/cpp] Hope some of that makes sense... Edit: Now with 100% more explanation
Guys telling him the answer is just dumb.
[QUOTE=raccoon12;23370807][B]neither are c[/B], and use [noparse][cpp]code[/cpp][/noparse] for code[/QUOTE] Wrong.
I'm having some problems with member initialisation in c++,I'm trying to write a 'World' class that takes a sf::RenderWindow in it's constructor before it takes over for the rest of the program. But I'm having problems initialising some of the classes members that require arguments. [code] class World { //Functions public: [b] World(const sf::RenderWindow& _App) : App(_App) {Init();}; [/b] void Init(); // This will set everything up void Loop(); void Draw(); virtual ~World(); protected: private: // Variables public: [b] // SFML const sf::RenderWindow& App;[/b] sf::View View; sf::Vector2f viewPosition; sf::Vector2f viewSize; // Misc double dt; // Box2D [b] b2Vec2 gravity; static const int pIterations = 2; static const int vIterations = 6; static const bool doSleep = true; b2World world; [/b] }; [/code] I've got the RenderWindow bit working, but the bolded code under 'Box2D' is where I'm having my problem. The constructor for b2World requires two arguments, a b2Vec2 (gravity) and a boolean (doSleep). I tried initialising the gravity member as a static const but that just threw errors at me (it takes 2 floats). What do I need to do to get this code to work? How do I initialise these members properly?
If I have a class that needs to be accessed by several classes, is it best to pass a reference or pointer to it to all those classes?
Well you are defining a class, not an instance, so initialise them in the constructor. [editline]02:58PM[/editline] [QUOTE=Overv;23378894]If I have a class that needs to be accessed by several classes, is it best to pass a reference or pointer to it to all those classes?[/QUOTE] A reference because then you can be sure you aren't going to delete it and cause a shitstorm. (I guess if it's off the stack it doesn't really matter though)
[QUOTE=blankthemuffin;23377342]Guys telling him the answer is just dumb.[/QUOTE] I was kinda expanding on raccoon12's answer a bit, and I was in too much of a rush to explain each one. I'll edit now
[QUOTE=Jallen;23378941]A reference because then you can be sure you aren't going to delete it and cause a shitstorm. (I guess if it's off the stack it doesn't really matter though)[/QUOTE] I would use a reference, but the class is passed by a DLL.
[QUOTE=Overv;23379064]I would use a reference, but the class is passed by a DLL.[/QUOTE] [cpp]myClass& getMyClass(){ return *myDllClassGetter(); }[/cpp] [editline]04:56PM[/editline] [QUOTE=Chris220;23376828]1.) I THINK is false, not 100% sure -> I think it's false because an "Accessor", as the name suggests, provides access to a member variable. Now, I'm not entirely sure, but I think it just means you can get the value of the variable, rather than changing it.[/QUOTE] You can do both if you provide a getter as well as a setter. The way the question is written makes me confused, I don't think it's right what it says. Sounds more like a bit of mumbo-jumbo to me :S [QUOTE=Chris220;23376828]2.) Is C (Assuming that two constructors for the same class still counts as 2) -> The SecretType class has two constructors: [cpp]secretType(); secretType(int a);[/cpp] Any function inside a class with the same name as the class and no return type is a constructor.[/QUOTE] Sure they do. However, it is not clear if that also includes implicitly generated constructors, like a copy-constructor. [editline]04:58PM[/editline] [QUOTE=Mattz333;23378457]I'm having some problems with member initialisation in c++,I'm trying to write a 'World' class that takes a sf::RenderWindow in it's constructor before it takes over for the rest of the program. But I'm having problems initialising some of the classes members that require arguments. [code] class World { //Functions public: [b] World(const sf::RenderWindow& _App) : App(_App) {Init();}; [/b] void Init(); // This will set everything up void Loop(); void Draw(); virtual ~World(); protected: private: // Variables public: [b] // SFML const sf::RenderWindow& App;[/b] sf::View View; sf::Vector2f viewPosition; sf::Vector2f viewSize; // Misc double dt; // Box2D [b] b2Vec2 gravity; static const int pIterations = 2; static const int vIterations = 6; static const bool doSleep = true; b2World world; [/b] }; [/code] I've got the RenderWindow bit working, but the bolded code under 'Box2D' is where I'm having my problem. The constructor for b2World requires two arguments, a b2Vec2 (gravity) and a boolean (doSleep). I tried initialising the gravity member as a static const but that just threw errors at me (it takes 2 floats). What do I need to do to get this code to work? How do I initialise these members properly?[/QUOTE] You using C++0x? I think this way of initialization is not available in former C++ versions. Unless it's some funky compiler extension. Anyway, which errors did you get? And what's the code you used to initialize world?
[QUOTE=ZeekyHBomb;23379616][cpp]myClass& getMyClass(){ return *myDllClassGetter(); }[/cpp] [editline]04:56PM[/editline] You can do both if you provide a getter as well as a setter. The way the question is written makes me confused, I don't think it's right what it says. Sounds more like a bit of mumbo-jumbo to me :S Sure they do. However, it is not clear if that also includes implicitly generated constructors, like a copy-constructor. [editline]04:58PM[/editline] You using C++0x? I think this way of initialization is not available in former C++ versions. Unless it's some funky compiler extension. Anyway, which errors did you get? And what's the code you used to initialize world?[/QUOTE] Nevermind, figured out how I needed to fix it. I never realised that member constructors could be called with the correct arguments in the 'World' classes constructer. ie: [code] World(const sf::RenderWindow& _App) : App(_App) {Init();}; Changed to: World(const sf::RenderWindow& _App) : App(_App), gravity(0,-9.8f), world(gravity, doSleep) {Init();}; Works ( didn't realise that I could call world/gravity member constructors, I thought it was just for assignment) [/code]
[QUOTE=Jallen;23377785]Wrong.[/QUOTE] what?
[QUOTE=raccoon12;23382841]what?[/QUOTE] You said number 2 isn't C, but it is :P
I need help getting laid [editline]11:00AM[/editline] Actually, that's as far from the truth as possible. BUT, I have a really random question. In Excel, I'm trying to edit a spreadsheet I've been working on for the last week. But everything is grayed out, and all I can do is copy/select boxes. I can't type, I can't edit, I can't save. Help? It isn't in read-only mode, I'm clueless.
[QUOTE=Chris220;23383033]You said number 2 isn't C, but it is :P[/QUOTE] -snip- I thought he was asking if the language was C, probably should have read the whole thing
[QUOTE=ZeekyHBomb;23379616] You using C++0x? I think this way of initialization is not available in former C++ versions. Unless it's some funky compiler extension.[/QUOTE] You're confusing the initializer-list syntax with constructor delegation. Initializer lists have been available for a long time. [cpp] class B { public: B(int foo) : foo(foo) {} // initializer list private: int foo; }; class A : B { public: A(int foo) : B(foo) {} // explicitly call base constructor to pass arguments A() : A(0) // C++0x: constructor delegation { otherInit(); } private: void otherInit(); }; [/cpp] [QUOTE=Mattz333;23381928]Nevermind, figured out how I needed to fix it. I never realised that member constructors could be called with the correct arguments in the 'World' classes constructer. ie: [code] World(const sf::RenderWindow& _App) : App(_App) {Init();}; Changed to: World(const sf::RenderWindow& _App) : App(_App), gravity(0,-9.8f), world(gravity, doSleep) {Init();}; Works ( didn't realise that I could call world/gravity member constructors, I thought it was just for assignment) [/code][/QUOTE] Any reason your Init function is public?
No, I was talking about this stuff: [cpp]static const int pIterations = 2; static const int vIterations = 6; static const bool doSleep = true;[/cpp]
[QUOTE=jA_cOp;23388111]You're confusing the initializer-list syntax with constructor delegation. Initializer lists have been available for a long time.[/QUOTE] What is this nonsense, initializer lists are C++0x, there's only been varargs.
[QUOTE=ZeekyHBomb;23388326]No, I was talking about this stuff: [cpp]static const int pIterations = 2; static const int vIterations = 6; static const bool doSleep = true;[/cpp][/QUOTE] Ah, I see - but those aren't C++0x either. static const variables do not have linkage, be it part of a class or not. [QUOTE=esalaka;23388660]What is this nonsense, initializer lists are C++0x, there's only been varargs.[/QUOTE] Initializer lists are not at all related to varargs.
[QUOTE=jA_cOp;23388757]Initializer lists are not at all related to varargs.[/QUOTE] Yeah, I was thinking of that C++0x thing that looks like varargs but is actually useable. Probably I should actually read before I post next time...
[QUOTE=esalaka;23389898]Yeah, I was thinking of that C++0x thing that looks like varargs but is actually useable. Probably I should actually read before I post next time...[/QUOTE] Probably thinking of variadic templates, which can be used for type-safe varargs.
[QUOTE=jA_cOp;23388111]Any reason your Init function is public?[/QUOTE] Just 'Cause
I'm having some problems with SFML post effects. Code: [cpp] sf::Image buff(800,600); sf::PostFX ef; ef.LoadFromFile("e.sfx"); ef.SetTexture("tex",&buff); ef.SetParameter("pos",0.f,0.f,0.f); [/cpp] Content of e.sfx (yes it is in the right folder) [code] texture tex vec3 pos effect { vec4 pix = tex(_in); _out = pix; } [/code] This error prints to the console window: [code] Parameter "pos" not found in post-effect [/code] I bet it's got something to do with data types:saddowns:
[QUOTE=Mattz333;23390638]Just 'Cause[/QUOTE] thats a good reason All right I got 10 questions, I have an idea for all of them, but i just want to make sure so I can get them right Edit: please just dont give me the answer for the ones that i have no idea or put no comment on, and if you know the answer to only one of them thats fine too! [CODE]Consider the accompanying class definition, and the declaration: rectangleType bigRect; Which of the following statements is correct? A) rectangleType.print(); B) rectangleType::print(); C) bigRect.print(); D) bigRect::print(); Lol I feel like I am missing something --------------------------------- Which of the following correctly declares and initializes alpha to be an array of four rows and three columns and the component type is int? A) int alpha[4][3] = {{0,1,2} {1,2,3} {2,3,4} {3,4,5}}; B) int alpha[4][3] = {0,1,2; 1,2,3; 2,3,4; 3,4,5}; C) int alpha[4][3] = {0,1,2: 1,2,3: 2,3,4: 3,4,5}; D) int alpha[4][3] = {{0,1,2}, {1,2,3}, {2,3,4}, {3,4,5}}; I belive its a or b ---------------------------------- Which of the following is a legal C++ function definition? A) void funcAlpha(int u, double v &) { cout << u << " " << v << endl; } B) void funcAlpha(int #, double #) { cout << u << " " << v << endl; } C) void funcAlpha(int &, double &) { cout << u << " " << v << endl; } D) void funcAlpha(int u, double& v) { cout <<u << " " << v << endl; } i believe its d ----------------------------------- Consider the following code. (Assume that all variables are properly declared.) cin >> ch; while (cin) { cout << ch; cin >> ch; } This code is an example of a(n) ____ loop. A) sentinel-controlled B) flag-controlled C) EOF-controlled D) counter-controlled eof controlled right? ----------------------------------------- suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C Choose the value of ch3 after the following statement executes: cin >> ch1 >> ch2 >> ch3; A) 'A' B) 'B' C) 'C' D) '\n' ----------------------------------------- Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is: 15A 73.2 Choose the values after the following statement executes: cin >> x >> ch >> y; A) x = 15, ch = 'A', y = 73.2 B) x = 15, ch = 'A', y = 73.0 C) x = 15, ch = 'a', y = 73.0 D) This statement results in an error because there is no space between 15 and A. I think its A but d is messing with me ------------------------------------------ The values of an enumeration type cannot be output directly to the standard output device. A) True B) False I have no idea ------------------------ The declaration char str[] = "Sunny Day"; declares str to be a string of unspecified length. A) True B) False Im pretty sure this is false ------------------------------- enever the value of a reference parameter changes, the value of the actual parameter changes. A) True B) False I looked up actual and refrence paramaeters but didnt really help me ------------------------- The statement return static_cast<char>(x + 5); where x is an int variable, returns a char value in a value-returning function. A) True B) False [/CODE]
Where do you get these questions from? I'd quite like to do some to stretch my knowledge :3:
their from a book, which is for a class im taking in school Ill pm you the book
[QUOTE=shemer77;23405412] Consider the accompanying class definition, and the declaration: rectangleType bigRect; Which of the following statements is correct? A) rectangleType.print(); B) rectangleType::print(); C) bigRect.print(); D) bigRect::print(); Lol I feel like I am missing something [/QUOTE] It depends on the accompanying class definition, which you haven't provided. [QUOTE=shemer77;23405412] --------------------------------- Which of the following correctly declares and initializes alpha to be an array of four rows and three columns and the component type is int? A) int alpha[4][3] = {{0,1,2} {1,2,3} {2,3,4} {3,4,5}}; B) int alpha[4][3] = {0,1,2; 1,2,3; 2,3,4; 3,4,5}; C) int alpha[4][3] = {0,1,2: 1,2,3: 2,3,4: 3,4,5}; D) int alpha[4][3] = {{0,1,2}, {1,2,3}, {2,3,4}, {3,4,5}}; I belive its a or b [/QUOTE] It's D), none of the others are syntactically correct. [QUOTE=shemer77;23405412] ---------------------------------- Which of the following is a legal C++ function definition? A) void funcAlpha(int u, double v &) { cout << u << " " << v << endl; } B) void funcAlpha(int #, double #) { cout << u << " " << v << endl; } C) void funcAlpha(int &, double &) { cout << u << " " << v << endl; } D) void funcAlpha(int u, double& v) { cout <<u << " " << v << endl; } i believe its d [/QUOTE] You're right :) [QUOTE=shemer77;23405412] ----------------------------------- Consider the following code. (Assume that all variables are properly declared.) cin >> ch; while (cin) { cout << ch; cin >> ch; } This code is an example of a(n) ____ loop. A) sentinel-controlled B) flag-controlled C) EOF-controlled D) counter-controlled eof controlled right? [/QUOTE] Right again. This is possible because 'cin' has a special operator overload which enables it to be implicitly cast to a pointer. The returned pointer is null if the stream has closed or an error occurred, hence terminating the loop. [QUOTE=shemer77;23405412] ----------------------------------------- suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C Choose the value of ch3 after the following statement executes: cin >> ch1 >> ch2 >> ch3; A) 'A' B) 'B' C) 'C' D) '\n' [/QUOTE] ch1 gets the first character, which is 'A'. ch2 gets the second, which is a space. ch3 thus ends up with the third character, 'B'. [QUOTE=shemer77;23405412] ----------------------------------------- Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is: 15A 73.2 Choose the values after the following statement executes: cin >> x >> ch >> y; A) x = 15, ch = 'A', y = 73.2 B) x = 15, ch = 'A', y = 73.0 C) x = 15, ch = 'a', y = 73.0 D) This statement results in an error because there is no space between 15 and A. I think its A but d is messing with me [/QUOTE] It is indeed A. [QUOTE=shemer77;23405412] ------------------------------------------ The values of an enumeration type cannot be output directly to the standard output device. A) True B) False I have no idea [/QUOTE] That would be false, but of course, it would have its numeric representation, so the question is arguably ambiguous. [QUOTE=shemer77;23405412] ------------------------ The declaration char str[] = "Sunny Day"; declares str to be a string of unspecified length. A) True B) False Im pretty sure this is false [/QUOTE] The compiler does in fact know the length of str, you can test this like so: [cpp] char str[] = "Sunny Day"; std::cout << sizeof(str) << std::endl; [/cpp] (Is your book a bit out of date? The type of a string literal is "const char[]", not "char[]", in modern C++) [QUOTE=shemer77;23405412] ------------------------------- enever the value of a reference parameter changes, the value of the actual parameter changes. A) True B) False I looked up actual and refrence paramaeters but didnt really help me [/QUOTE] This is true, although it's a bit poorly put. The reference [I]is[/I] the parameter, so there's no 'actual parameter'. Take this example: [cpp] #include <iostream> void setToOne(int& i) { i = 1; } int main() { int i = 0; setToOne(i); std::cout << i << std::endl; } [/cpp] If you had received 'i' by value (as opposed to by reference) in 'setToOne', the output would be 0. [QUOTE=shemer77;23405412] ------------------------- The statement return static_cast<char>(x + 5); where x is an int variable, returns a char value in a value-returning function. A) True B) False [/QUOTE] This is true, but this is casting basics, so you should really just look it up. if anyone has any corrections or injections to make, please help me out :v:
Sorry, you need to Log In to post a reply to this thread.