Tuesday, April 15, 2014

# Include


Hi everyone! Whilst I do not much progress I've been busy with classes, free fort again came up a little C + + classes have been able to proceed. Who was waiting for a long time really sorry for those who want to convey. From previous courses, while learning adele about classes and operator overloading in C + + and saw a new taste, then from now on in earnest dark broth wooryeonae C + + classes that are going to be like.
Maybe if people come along nicely my last lecture courses, adele it is the memory of who was to create a class MyString is nasil. C language-style strings are so many various problems (for example, once the length of the string can not find the last one to read that any NULL characters.) Can handle strings need something new, you had to continue .
(Enter adele this string term to introduce some of the technologies, for a short string without allocating adele memory dynamically and just keep a local variable, when you copy a string that does not change adele the contents of the string copied to the actual data Rather than copying the original string, adele but the point to so many efforts to improve the speed to be combined)
}
if (s! = t) {
if (s! = t) cout << s << "and" << t << "is different from" << endl; Such as == and! = October, it is impossible to compare. (Because it is the address of the string to compare value portal! - I do not ever remember back to those reported in this course, please!), But the string class == and! = Operator overloading, and all of them perform well compared to the . As well as the size comparison> =, <= 's the also performed well. String functions and features provided by the fact that I have which are introduced in the course beyond just filling a huge place not many about. Introduce only the most used features on all the information laid out for you is if you want the http://en.cppreference.com/w/cpp/string/basic_string. Aside from the length function here to look at the string to insert between the strings and insert functions, erase to erase a specific location or replace the string adele substitution, etc. There are many many useful functions.
The purpose of the program, we need to create adele a company to calculate the employee's salary and wages per month for a total of how much you should spend the money that tell a simple adele program. Then once you have the information to each employee in the class to hold the data presumably create. The data required for the employee's adele name, age, job title, and a numeric value that corresponds to the rank of positions (for example, if one pyeongsawon, deputy Cotton 2 in this way) is about. Based on this, simply configure the class will be able to look at is as follows: Â.
{
};
Recall that made MyString term, always processing data dynamically allocated in order that the two parameters are required but, the total size of the current allocated one and the other one is that the amount actually used in yijiyo. adele Ought to do so much more than just the amount of allocated size can prevent accidental use. So we tell alloc_employee size of the array is allocated and, current_employee employees currently enrolled in employee_list adele I can see it.
current_employee + +;
{
for (int i = 0; i <current_employee; i + +) {
# Include <iostream>
age = employee.age;
{
/ / (Ie, the total number of employees assigned to more than the size of the current lot)
}
emp_list.add_employee (new Employee ("bakmyeongsu", 43, "deputy", 5));
Oh well so making four won submit application asking moment, through the infinite one firm receives from the contact. Deputy level over the tenure of administrative data by including additional salary malyijiyo dont. So I wept gamyeo Manager class has been added to mustard adele to eat. In fact, almost the same, the Langley Employee class, I could not. Even more annoying is part of the Employee and Manager EmployeeList class that is to be processed separately. Anyway, let's configure one Manager class.
position = manager.position;
Employee class and as good as the previous, int year_of_service added, you can see that one. Of course calculate_pay function to calculate the monthly salary, or output the information adele has been changed adele slightly print_info function. Let's take a look at this time EmployeeList class.
EmployeeList (int alloc_employee): alloc_employee (alloc_employee)
}
}
delete [] manager_list;
/ / Copy constructor
return 200 + rank * 50;
name = manager.name;
}
}
int current_employee_num ()
}
emp_list.add_employee (new Employee ("GNP", 34, "pyeongsawon", 1));
In fact, there's something in the words inherited the 'bite' that takes meaningful use. That inheritance in C + +, inheritance of information received through the other classes available. One is applied immediately before the Employee and Manager classes, first create a simple class inheritance in C + +, how to use a feature called Let's look at whether.
string s;
cout << "child class" << endl;
{
};
{
public:
what ();
This time, both the Child and Parent on what () function is defined. In this case, Child, as shown below in what calls what happens adele when you call it? Some people have problems on the compilation can not we think that there is, in fact, the two functions of the same name, but (even arguments too, but), because it is defined adele in another class are treated as different functions. (Of course, Child in on what has been a problem if the two will be defined)
void what () {cout << parent_string << adele endl;}
error C2248: 'Parent :: parent_string': cannot access private member declared adele in class 'Parent'
What the hell do you mean no? Wilderness at best been inherited, you mean you can not access it. But the fact that the private member variable, except that in any case you can not access his class. adele However, often derived class (a class that inherits - in case the Child class) from the original parent class (ie, where Parent) direct access to the data you need. For example, in the case of our example Employee class inherits from a parent class when it receives the Manager class, name and age itgetjiyo need to access. However, they are not private, because the approach.
{
void what () {cout << child_string << endl;}
If the above If you like the parent class inherited form of public access to works without any impact indicators. This means that the derived class is the same position adele in the public and the public, protected and will remain protected, private will remain private. If you have ten thousand and one in a derived class inherits from protected position changes in the rest of the public is protected, will remain the same. If you have ten thousand and one private in a derived class inherits all the entries will be private access directives. In fact, let's take a look at the following example.
# Include <iostream> # include <string> using namespace adele std; class Parent {public: string parent_string; Parent (): parent_string ("parent") adele {cout << "parent class" << endl; } Void what () {cout << parent_string << endl;}}; class Child: private Parent {string child_string; public: Child (): child_string ("child"), Parent () {cout << "child class" << endl; } Void what () {cout << child_string << endl;}}; int main () {Parent p; / / Parent adele parent_string the public, so the / / accessible from the outside of course. cout <<

No comments:

Post a Comment