Class with constructor | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Class with constructor

Help me please to create a class with constructor in witch i need to make 4 any operations : cycle with 'while',cycle 'for',cases and logic.

17th Oct 2017, 9:45 PM
Jimmy Pub
Jimmy Pub - avatar
39 Answers
+ 2
Good. Then you need a constructor with: 1) for loop 2) while loop 3) switch 4) i'm not sure what you meant by 'logic', maybe if statements? Assuming you know what a constructor is, and that we have total freedom of the purpose of operations, we may choose, for example to initialize some arrays with the loops (so we need some array members). Also we need some logic. For that, we may invent something later, but first one question: Does this class need to be usefull, or it may be any syntetic demonstration of the 4 language features?
17th Oct 2017, 10:32 PM
deFault
+ 1
Alright then, share the playground code. I want to see what you come up with.😼
17th Oct 2017, 10:29 PM
Manual
Manual - avatar
+ 1
Make the code. Computer copy paste the url. (on phone.) Then press + INSERT press code. | \/
17th Oct 2017, 10:31 PM
Manual
Manual - avatar
+ 1
Still no code?
17th Oct 2017, 11:01 PM
deFault
17th Oct 2017, 11:15 PM
Jimmy Pub
Jimmy Pub - avatar
17th Oct 2017, 11:38 PM
Jimmy Pub
Jimmy Pub - avatar
+ 1
what is try making a destructor instead of ~MYARRAY;
17th Oct 2017, 11:41 PM
Manual
Manual - avatar
+ 1
https://code.sololearn.com/cpsMLZ8Sm9y2/#cpp Here you go. The class' usefulness is doubtful, but I thought all the stuff should be in the constructor.
17th Oct 2017, 11:53 PM
deFault
+ 1
Сишку я после универа не знал. Юзал, в основном VB.net. После универа меня поперло в линукс, захотел там научиться писать графические программы, а лучше кросплатформенные. Так, с минимальными знаниями, я взялся за изучение Qt. Там у них какая-то стандартная книжка была. Дальше практика, практика, практика… По Си++ читал только Страуструпа один раз и то давно.
18th Oct 2017, 12:16 AM
deFault
0
I really need your help,i don't know how is it works .
17th Oct 2017, 10:12 PM
Jimmy Pub
Jimmy Pub - avatar
0
What do you not understand about creating that class? All the required info is present in the C++ tutorial, that you have 80% complete. I would gladly help you, but it appears like this is your homework, that you want someone to do for you. And such approach will not teach you anything. Try to do it yourself, ask further questions if you don't understand anything specific about the task.
17th Oct 2017, 10:13 PM
deFault
0
Start by creating a C++ code. Then you need to create a class. Do you know what a class is and how to create it?
17th Oct 2017, 10:22 PM
deFault
0
Yes i know
17th Oct 2017, 10:24 PM
Jimmy Pub
Jimmy Pub - avatar
0
I need to understand and then should be usefull. And yep,statements.
17th Oct 2017, 10:35 PM
Jimmy Pub
Jimmy Pub - avatar
0
@Manual i don't totally understand :d my engish language skill is low but better then programming btw :c
17th Oct 2017, 10:37 PM
Jimmy Pub
Jimmy Pub - avatar
0
What i need to write?
17th Oct 2017, 11:11 PM
Jimmy Pub
Jimmy Pub - avatar
0
At least create a class with a constructor. Declare a variable of that class in main. And then we may come up with some idea on what to do in it, and implement the constructor's functionality.
17th Oct 2017, 11:14 PM
deFault
0
First of all, there's no constructor. Constructor is declared like this: class MyClass { public: MyClass() { // Here is the constructor body } } But at least you made your class. That's a starting point. Let me come up with something to implement. I'll post it here in a min…
17th Oct 2017, 11:19 PM
deFault
0
Now it's working,tryin to make constructor .
17th Oct 2017, 11:21 PM
Jimmy Pub
Jimmy Pub - avatar
0
1. Make an enum PrintType, that has values like NONE, ODD, EVEN, ALL 2. Create a class MyClass. 3. Create two class members: mSize of type int, and int *a. We will use 'a' as an array, and store it's size in mSize. 4. Create the class' constructor and destructor. In the destructor we will delete our array. 5. In main, create a variable of that class. When that's done, we will fill our constructor and destructor body. Our class' constructor will create an internal array of size passed to the constructor, initialize it to a value passed to the constructor, and print it out as specified by the constructors' parameter of type PrintType (possible values: NONE, ODD, EVEN, ALL). If you have troubles doing any step, ask. I already have that code created, just want to walk you though the creating process step-by-step.
17th Oct 2017, 11:29 PM
deFault