Class with constructor | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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