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.
39 Antworten
+ 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.