Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
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.
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?
+ 1
Alright then, share the playground code.
I want to see what you come up with.š¼
+ 1
Make the code.
Computer copy paste the url.
(on phone.)
Then press
+ INSERT
press code.
|
\/
+ 1
Still no code?
+ 1
https://code.sololearn.com/croBBqg0wVTB/?ref=app
What's wrong there?
+ 1
what is try making a destructor instead of ~MYARRAY;
+ 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.
+ 1
Š”ŠøŃŠŗŃ Ń ŠæŠ¾ŃŠ»Šµ ŃŠ½ŠøŠ²ŠµŃŠ° Š½Šµ Š·Š½Š°Š». Š®Š·Š°Š», Š² Š¾ŃŠ½Š¾Š²Š½Š¾Š¼ VB.net. ŠŠ¾ŃŠ»Šµ ŃŠ½ŠøŠ²ŠµŃŠ° Š¼ŠµŠ½Ń ŠæŠ¾ŠæŠµŃŠ»Š¾ Š² Š»ŠøŠ½ŃŠŗŃ, Š·Š°Ń
Š¾ŃŠµŠ» ŃŠ°Š¼ Š½Š°ŃŃŠøŃŃŃŃ ŠæŠøŃŠ°ŃŃ Š³ŃŠ°ŃŠøŃŠµŃŠŗŠøŠµ ŠæŃŠ¾Š³ŃŠ°Š¼Š¼Ń, Š° Š»ŃŃŃŠµ ŠŗŃŠ¾ŃŠæŠ»Š°ŃŃŠ¾ŃŠ¼ŠµŠ½Š½ŃŠµ. Š¢Š°Šŗ, Ń Š¼ŠøŠ½ŠøŠ¼Š°Š»ŃŠ½ŃŠ¼Šø Š·Š½Š°Š½ŠøŃŠ¼Šø, Ń Š²Š·ŃŠ»ŃŃ Š·Š° ŠøŠ·ŃŃŠµŠ½ŠøŠµ Qt. Š¢Š°Š¼ Ń Š½ŠøŃ
ŠŗŠ°ŠŗŠ°Ń-ŃŠ¾ ŃŃŠ°Š½Š“Š°ŃŃŠ½Š°Ń ŠŗŠ½ŠøŠ¶ŠŗŠ° Š±ŃŠ»Š°. ŠŠ°Š»ŃŃŠµ ŠæŃŠ°ŠŗŃŠøŠŗŠ°, ŠæŃŠ°ŠŗŃŠøŠŗŠ°, ŠæŃŠ°ŠŗŃŠøŠŗŠ°ā¦ ŠŠ¾ Š”Šø++ ŃŠøŃŠ°Š» ŃŠ¾Š»ŃŠŗŠ¾ Š”ŃŃŠ°ŃŃŃŃŃŠæŠ° Š¾Š“ŠøŠ½ ŃŠ°Š· Šø ŃŠ¾ Š“Š°Š²Š½Š¾.
0
I really need your help,i don't know how is it works .
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.
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?
0
Yes i know
0
I need to understand and then should be usefull. And yep,statements.
0
@Manual i don't totally understand :d my engish language skill is low but better then programming btw :c
0
What i need to write?
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.
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ā¦
0
Now it's working,tryin to make constructor .
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.