Hello nomnomu,
"<iomanip>" as the name tends to imply works with "<iostream>" to manipulate what is in a "cout" statement. You are likely to first learn about it when you start using "doubles" to store numbers and "setprecision" would be the first part you learn. The "std::setw()" is not that hard to understand. It creates a block to put something in. Varying the width of that block is used to space columns across the screen.
I do not know where you came up with needing "<cstring>", but this is the C++ version of the C header file "<string.h>". "string.h" and the C++ "string" are not the same nor can they be used the same. "string" contains the string class and all the functions that go with the class. "string.h" knows nothing about classes.
You have changed to using "_getch()". I am not sure if Dev C++ needs this, but I know my MSVS 2017 does. Whichever works for you the header file "conio.h" is still needed.
"int main()" should never need to be forward declared, or prototyped, if you have to then there is something else wrong somewhere.
In the "Property" class your 1st variable is "int no;". Is the word no, the opposit of yes, or short for number. And what is it doing here when it should be in the "Details" class where it is needed to keep track of the array. Still need a better name and do not be afraid of longer variable names.
A suggestion:
1 2 3 4 5 6 7 8
|
class Property
{
//Private attribute (Encapsulation)
private:
int no;
string mType;
string mName;
string mStatus;
|
I have also seen:
1 2 3 4 5 6 7 8
|
class Property
{
//Private attribute (Encapsulation)
private:
int no;
string m_type;
string m_name;
string m_status;
|
Whether you use the single letter "m" or the "m_" it helps to set off the member variables of a class from a regular variable. So in a line like:
void set_preset(int o, string y, string a, string u)
you could writhe the function as:
1 2 3 4 5 6 7
|
void set_preset(int no, string type, string name, string status)
{
mNo = no;
mType = type;
mName = name;
mStatus = status;
}
|
And your code is much easier to follow and understand.
I am not the expert on classes, but I do not believe that "void statement()" is "Polymorphism", but I could be wrong.
In the "Details" class in the private section this is where you need a variable to keep track of how much of the array is used. Having to call a "get" or "set" function just to use a private variable from another class is wrong.
In the "presetData" function you are good from "[0] to [4]", but "[5] - [9]" are not necessary. I see now that the "no" in "Property" is a counting number. If you are using this number in the "Add" function that is why you are off.
In "Details" when you create the array it contains 10 elements of the object "Property". The "std::string"s are empty and have no value, but the "no" is an uninitialized variable and has a garbage value until you give it something.
The "6 - 10" is OK, but you need to remove the space from the double quotes.
This function:
1 2 3 4 5
|
void Property::set_newproperty()
{
//Local variable
int countafterpreset = 6; // <--- You only preset 5 usable elements not 6.
no = countafterpreset; // <--- "no" is the wrong variable to be using here.
|
Technically you have preset all 10 elements of the array, but only the first 5 have usable information.
As you say "countafterpreset" is a local variable defined when the function and destroyed when the closing } is reached and the function looses scope only to be remade the next time the function is called. This should not be a local variable, but retrieved from the "Details" class. You will have to pass that variable from the "Details::addDetails" function, (by reference), so the proper variable can be updated.
In the "Details::addDetails" function you define the local variable "counter" you even give it the correct value. Add the new information and the last line adds 1 to counter just before the variable is destroyed and the new value is lost.
As I happen to notice in "void Details::addDetails()", that would be the 2nd one, and why the compiler did not find this an error I do not know. Maybe it is saving it for later when the other errors are fixed.
Either I did something wrong in the copy and paste or you changed you code after you posted it. If you changed the code do not do that. It confuses people and makes the thread hard to follow.
There is something to work on for awhile while I get the code to compile and run.
Andy