Friday, 2 December 2011

Managing Professional Development

Managing Professional Development
    Introduction
All the human being are contestant, and everybody has different qualities and capabilities which they acquire throughout the learning of their life. We keep on learning throughout our life time. So, those learned skills help us in workplace environment, where everybody has to contest with his colleagues in order to prove his 
efficiency and power of continence.
The performance and future position of a venture or organisation is totally dependent upon the professional condition of its employees and workers. A healthy developed management can lead an organisation toward his main dream or helps in assessing its main aims and objectives.
To be effective the development of workplace and managerial skills must return the current and projected essentials of the organization. It is a perilous responsibility of senior management to recognise the core consistencies of the enterprise and to ensure that the consistencies required by managers, specialists and the workforce in general are adequate and adequate. Contestant people are the key to future success and offer organizations their only sustainable competitive advantage.
Professional development is an on-going process involving of activities that enhance professional growth. It may include workshops, independent reading and study, conferences, and consultation with peers and experts. Since its primary purpose is to benefit the individual, professional development should be planned and managed by the individual. As a part-time teacher of adults, you may develop your professional development plan in consultation with your supervisor, and you may receive help from others in evaluating and modifying teaching practices.








2.    P1 (13.1.01)
Performance management:
Performance management is a process which is used to measure the performance of the organisation, individuals and employees with in any organisation led by line managers.
                                    (Michael Armstrong)
Performance management refers to the skills of attracting highly skilled workers, of integrating new workers, and developing and retaining current workers to meet current and future business objectives. Performance management in this context does not refer to the management of entertainers. Companies engaging in a performance management strategy shift the responsibility of employees from the human resources department to all managers throughout the organization.
 The process of attracting and retaining profitable employees, as it is increasingly more competitive between firms and of strategic importance, has come to be known as "the war for performance." Performance management is also known as HCM (Human Capital Management).            
Performance review:
performance is a necessary step in order to keep organisation on track. Likewise, performance management is also a vital tool used by managers in order to keep track of individuals and their working capabilities. Following are some golden rules which could by prove as great helping material for mangers to measure the performance.

Be prepared:
Firstly, if we are justifying our own performance, we have to be ready to face any kind of challenges that may come in our business management life.
Discuss performance:
I order to review individual or own performance discussion should be made which must be factual and full of evidences. That discussion should not include any individual opinion.
Encourage analysis of performance:
While reviewing performance there is no need to mere appraise the performance. It should be critically analysed by keeping in view all the well and bad performances.
Assessing own performance:
As a performance analyser, there are few tasks which must be kept in mind while assessing the own performance.
1.      Seeing yourself as others see you.
2.      Being overly critical of yourself.
3.      Understanding your theories.
4.      Setting realistic standards for you.
5.      Attempting to master things beyond your reasonable control.
One way to handle all of this is to think like a project manager in assessing yourself.  This can help to remove some of the emotion and personal attachment from the effort. For example, you can:
1.      Ask others for an honest performance assessment of yourself, and pointed ask for feedback about specific aspects of your performance, maybe about a very specific situation you are handling.
2.      Document your beliefs. What is most important to you?  What is least important?  To what extent are you really familiar with your deep seated beliefs?  Recurring stresses can give you a hint.
3.      What job performance standards are you setting for yourself? Are you stretching far enough?  Are you setting yourself up for success?

3.    P2 (13.1.02)
Conduct a self-assessment inventory:

Name
4.    Mr. John W loger
address
London, England
Position
Cashier
Department
HR
Date of birth
02-03-1980
                                                                                                                                                                                                                               



Personal profile

I am reliable individual who believes that education and hard work is the key to progress forward in life. I am able to communicate with individuals of all ages and of all different backgrounds. I am extremely polite and like to treat others how I would like to be treated.
I am able to apply knowledge and understanding to practice and to analyze any problem if and when they occur. I have good organizational skills and I am also very contestant in liaising with people.
I am a quick learner and I am able to follow instructions well. I am also happy to share knowledge with others. I enjoy working with a team but also enjoy opportunities to develop my personal role.
I am an energetic and enthusiastic person who enjoys a challenge and achieving personal goals. My present career aim is to work within IT because I enjoy working with computers, I enjoy the environment and I find the work interesting and satisfying. The opportunity to learn new skills and work with new technologies is particularly attractive to me.


Experience

Shepherd foods                           sales assistant/cashier                                      August2010- present
I am working as a sales assistant for shepherd foods. My duties include serving customers and helping them in finding different products available at the shop. Moreover I also work on till as a cashier. I find myself so convenient with all the workers and I produce good output as a team member.                                                                               
St. Francis Library                         Library' Assistant                                               August 2008- January 2009
I have worked as a library assistant at my School for one year. I have good experience of working as a team member to ensure that we provide good quality of service for the students and customers who came to use the library facilities.  I have good computer skills. I have also experience of handling library database.

Interest and Achievements

I am interested in reading books and learning new things. I try to get information about latest                                      
Technology. Mostly, I spend my free time in playing football and different games. I also surf internet to
Browse about economics and marketing. 
I have worked for ESEF (Elementary society to excel in future) NGO as a volunteer. I supported majority
Of student and did their career counselling via this organization. We used to collect charity for students
Who were unable to pay their school dues?  (www.esef.org.pk)

SKILLS
I have good customers’ service skills. I can work as a good team member.
I have good computing skills in following:
Software’s and programming
Microsoft office including Microsoft word, Excel, power point and Access.
Multimedia Design and website designing
Computing             GW Basic, C++, HTML, OOP, OFFICE MANAGEMENT                                  



Date:
Employee signature

Print Name
Employer name
Print name





4.     P3 (13.1.03):
devise and maintain a current CV and/or portfolio of work

Resume


John W. logers
938 Adams St
Anoka, MN 55303
763-229-3958
johnhelgeson@mnsu.edu


Objective:
To help people better their life. I enjoy working with others and working in a business where I can be of help to someone. Children are my passion, my dream job is to work with children and help them learn.



Skills:
Microsoft Office
Microsoft Publisher
3 Years of Retail Experience
Great Communication Skills
Can answers Telephones

 Enjoy a Challenging Career
 Very Experienced in Customer Service

Education
St. John High School
June 200
Graduated with high honours and a 3.2 GPA
 London city university
Secondary Education, History and Sociology
Present

Was on Dean's list with a 3.3 GPA
May 2009



Experience

Guest Service Team Member at Coon Rapids and Mankato Target
November 2006- Current
Assist customers in a fun, fast, and friendly manor.
Trained in new cashiers
Work as a team with other employees

Volunteer Library Assistant
April 2007-June 2007
Assist a first grade teacher with grading, lesson planning, and tutoring.
Help students with reading and math skills

Volunteer Preschool Assistant
January 2007-April 2007
Assist children with snack, clean up, and activity time


Volunteer at Lincoln Community Centre
January 2009-May2009
Tutor ESL adults in math, reading, and science
Assist teachers with grading, lesson plans, and answering student's question

5.     P4
Devise a personal development plan to achieve personal targets and short and long term learning objectives:
Personal development plan should cover overall progress. A plan would be considered effective if it nurtures your personality on all fronts; like;

·        The career and the financial aspect
·        The social aspect
·        Relationships
·        Health
·        Emotional aspect

Personal development is independent of the age or gender of the person. Any day one decides, one can start working on developing the self and reap rich harvests in the form of higher productivity and satisfaction.

Another imperative aspect of personal development plan is that the enforcement of the plan is perennial; it is a 24/7 process; if focused on properly, it will give the best results. One has to be aware of it every moment of one’s life.

Before developing a personal development plan just ponder if it would help you. Analyze the areas where you need to emphasize and what approach you would take while developing a personal development plan.




What should a good personal development plan focus on?

A wide-ranging outline of a self-development plan could be as follows:

1.      List your Short and long term goals and career objectives.

The more one does on the career front, the better one feels. The craving to accomplish more takes precedence and the confidence of achieving all that you want to realise, soars high.

So the first step to develop a personal development plan is to make a list all that you’ve accomplished till now.
Look at it positively. See how your work has benefitted you all along.
Make another list of what more you want to accomplish. Incorporate into that list all the upcoming projects you’d like to undertake.

Think clearly how much exposure and experience will you derive by following each aspiration.
Also consider how strongly it would affect you if you fail to achieve those desired accomplishments.

Thus evaluate and prioritize the projects and goals for future. Set up a mandatory tag to the ones those are extremely important and set up a dead line for each of those important achievements which can act as mile stones in shaping up your career.

1.       Perform a SWOT analysis.

The first step to develop a personal development plan is to perform a SWOT analysis.
 By reviewing your strengths, weaknesses, opportunities and threats, give yourself a fair idea of where you stand and which areas you need to work on to accomplish the targets you had set for yourself in order to excel.
  
2.      Assess the resources available with you.

Check out all the resources you have and shortlist those you need and do not possess to accomplish your goals. Look at how you can use the ones which are available and how can you acquire those you lack.

According to the availability of the resources, if it’s required, modify the list of your desired accomplishments and the targeted goals.
This is a very important step to develop a personal development plan.

3.      Be an Opportunist.

Be observant, grab and hold the opportunities that arrive in front of you. Try to develop and advance yourself to the maximum with each experience.


4.      Incorporate learning naturally in your system.

Your personal development plan can be made successful only if followed diligently and applied throughout all times. Hence learning new skills and updating them should also come almost all the times, naturally and effortlessly.

5.      Discipline yourself for continued development and lifelong learning.

Develop self-discipline for continuing professional development. Personal development is a lifelong learning process which can be achieved through controlling your thoughts and training the mind to think in a required manner to achieve your aspirations.

6.      Try to keep yourself well informed and updated.

Try to keep yourself well informed about current condition and situations of surrounding.

6.      P5
Evaluate learning and development with original aims and objectives set in the development plan:

1.      Learning by swot analysis

SWOT analysis can help in assessing all the strengths, weakness, opportunities and threats regarding your personality. It is a good way of learning about your aims and objectives.
  
2.      Learning by assessing sources.

Assessing available sources can give a good opportunity to individual to come up with a plan in the business organisation.

3.     Learning by being an Opportunist.
 Being an optimist is also a great power for learning. As we can learn by critically analyzing a topic from different perspectives.


4.      Discipline yourself

Being a disciplined and well organised individual is also a nice way to sharpen your personality.

6.      Learning by being updated by current situation.

Being aware about what is happening around is also helpful in learning about different mysteries and thing happening around the world. It keeps your well aware about your economical and current statistical situation.

7.      P6
Reset objectives in light of evaluation and feedback:

Change a qualitative (and quantitative where possible) model to get the rationale of existing and future separation minima standards.
1.      Develop high-level advanced operational concepts which complement existing European initiatives and aimed to enable reduced separation minima.
2.      Identify, in collaboration with ICAO, EUROCONTROL, the FAA, ANSPS and national regulators how to accomplish the change for the modified separation minima.
3.      Prioritize and select (at least) three potential separation minima reductions for detailed safety, efficiency and economic assessment. The selection and periodization of the cases will be accomplished based in different criteria, apart from the level of attainment of a set of separation goals objectives, related to safety, technical viability, efficiency, stakeholder acceptance and also in terms of their sequence of implementation over time.
4.      Identify and apply methods to safely and cost-effectively assess the prioritized separation minima reductions.
5.      Feedback the outcome of the safety and economy assessments towards the operational concept designee



8.      P7
Identify and create solution to work based problems
Technically speaking, Work is the quantity of energy transferred from one system to another but for question based on this topic-
Work is defined as the amount of job assigned or the amount of job actually done.

Problem on work are based on the application of concept of ratio of time and speed.|
Work is always considered as a whole or one. There exists an analogy between the time-speed-distance problems and work.

Work based problem are more or less related to time speed and distance.

Above mentioned definition of work throws light on three important points.

Work = 1 (as it is always measured as a whole) = Distance

Rate at which work is done = speed

Number of days required to do the work = Time

IMPORTANT FORMULAE FOR WORK RELATED PROBLEMS
If A can do a piece of work in 'a' number of days, then in 1 day  of the work is done. Conversely, if a man does  of work in a day, then he can complete the work in   days.

Example: If a man can complete a work in 10 days. How much work he can do in 6 days?
Solution:


A man performs in 10 days = 1 work.
= A man will perform in 1 day =   work
If A is 'x' times as good a workman as B, then he will take   of the time by B to do the same work.
Example: If A can complete a work in 10 days and B are 100 faster than A. How much time B will take to complete the work?

Solution:

A takes to perform 1 work = 10 days. %

= B will perform the same work =   time than A.

= B will take to perform the same work = 

9.      P 8
Communicate in a variety of style and in good manner:
Communications 
-          Communication is a way to transmit your messages to others. It represents your behaviour you attitude and differ aspects of your personality.
-          Following are some consideration which must be followed while communication.
-          In Japan, business cards are called meishi. Japanese give and receive meishi with both hands. It should be printed in your home language on one side and Japanese on the other. Present the card with the Japanese language side up.
-          The card will contain the name and title along with the company name, address and telephone number of the businessman. In Japan, businessmen are call "sarariman." A sarariman who does not have a
-          Take special care in handling cards that are given to you. Do not write on the card. Do not put the card in your pocket or wallet, as either of these actions will be viewed as defacing or disrespecting the business card. Upon receipt of the card, it is important to make a photocopy of the name and title of the individual in your mind. Examine the card carefully as a show of respect.
-          In a business situation, business cannot begin until the meishi exchange process is complete.
-          The customary greeting is the bow. However, some Japanese may greet you with a handshake, albeit a weak one. Do not misinterpret a weak handshake as an indication of character.
-          If you are greeted with a bow, return with a bow as low as the one you received. How low you bow determines the status of the relationship between you and the other individual. When you bow keep your eyes low and your palms flat next to your thighs. The business card should be given after the bow. This is very important to remember.
10.  P9
Effective time management strategies:
Be prepared to make drastic changes. Be creative to find and introduce different ways of doing things. If you need a starting point sees the 'Pareto Principle' (80:20 Rules), to assess what efforts and activities are most productive, and which are not. (See also the acronyms PAY and MILE - warning: there is adult content on the acronyms page.)
Manage your emails and phone calls - don't let them manage you. Ideally check at planned times, and avoid continuous notification of incoming emails.
The more senior you are the more selective you need to be about when to be available to receive phone calls.
Really think about how you currently spend your time. If you don't know, keep a time log for a few days to find out there's a free time management time-log template tool here. Knowing exactly what's wrong is the first step to improving it.
Challenge anything that could be wasting time and effort, particularly habitual tasks, meetings and reports where responsibility is inherited or handed down from above. Don't be a slave to a daft process or system.
Download and use the free time management assessment tool at the free online resources section, which will help you or another person to objectively judge your time management, and underlying issues.
Review your activities in terms of your own personal short-term and long-term life and career goals, and prioritise your activities accordingly.
Plan preparation and creative thinking time in your diary for the long-term jobs, because they need it. The short-term urgent tasks will always use up all your time unless you plan to spend it otherwise.
Use a diary, and an activity planner to schedule when to do things, and time-slots for things you know will need doing or responding to. There's as ample with examples on the new time management section.

P10
Methods for learning and personality development
Personality:
 Personality is a combination of different thing which includes behaviour, attitude, thinking, feeling and acting in different circumstances.
Everyone wants to be attractive to others.  To that end, having a good personality is vital - probably even more so than good looks. In fact, approximately 85% of your success and happiness will be a result of how well you interact with others. Ultimately, it is your personality that determines whether people are attracted to, or shy away from you.
Methods of learning and development:

1.     Be a better listener.
a.     Jacqueline Kennedy Onassis was considered one of the most charming women in the world because she cultivated the skill of being an exceptional listener. She was known for the way she would look a person in the eyes, hang on their every word, and make them feel important. There is nothing more appealing than having someone listen to you intently making you feel like you're the only person in the world.
2.     Read more and expand your interests.
a.     The more you read and cultivate new interests, the more interesting you are to others. When you meet new people it gives you the opportunity to share what you know and to exchange your views with them.

3.     Have an Opinion.
a.     There is nothing more tiresome than trying to talk to someone who has no opinion on anything. A conversation has nowhere to go if you have nothing to expound on. If, however, you have an uncommon point of view or differing opinion, you are more interesting and stimulating to be with socially (unless you're a know-it-all, of course).  A unique outlook expands everyone's perspective.
4.     Meet New People.
a.     Make the effort to meet new people especially those unlike you. It not only exposes you to different cultures and alternative ways of doing things, it broadens your horizons. 
5.     Be yourself.
a.     The next most tiresome thing after having no opinions is trying to be something you're not. Molding yourself in order to fit in, or be accepted, usually backfires. Since each of us is unique, expressing that uniqueness is what makes us interesting. Attempting to be a carbon copy of someone else not only falls flat, but reveals a lack of authenticity. 

P11
Ways to encourage lifelong learning:

Lifelong learning:
Our lifelong learning policy for Scotland is about personal fulfilment and enterprise, employability and adaptability, active citizenship and social inclusion.
Lifelong learning is mainly about the training and learning that people can achieve after they leave school. We want to make it possible for more young people to stay on at school or college. And we want all pupils and students over 14 to gain work-based vocational learning and enterprise experience.

-          e-launching Individual Learning Accounts, to widen participation in adult learning
-          Asking the Enterprise Networks to strengthen Scotland's skills base. We have also asked them to make sure that Future skills Scotland and Careers Scotland have an increasingly active role in developing people's knowledge and understanding of the needs of the labour market
-          merging the Scottish Higher and Further Education Funding Councils
-          Promoting the Scottish Credit and Qualifications Framework to give people a better understanding about how they can build on their qualifications. This will help employers and individuals to see where any qualification sits in relation to another
-          improving the quality and consistency of information for learners, by developing learn direct Scotland’s national database of learning opportunities
-          improving the literacy and numeracy skills of 150,000 adults by 2006
-          piloting Business Learning Accounts with small businesses, providing them with the tools to link training needs with business growth
-          encouraging community-based learning
-          increasing the potential for students to transfer from college to university, by greater collaboration between the Scottish Qualifications Authority, colleges and universities when they develop qualifications

P12
Different sources of Primary and secondary Data:
Primary data:
There are different ways to collect primary data. For example primary data can be collected by following sources.
-         Surveys
-         Questionnaires
-         observations
-         interviews
1-    in-depth interviews
2-    structured interview
3-    unstructured interview
Sources of secondary research:
On the other hand, different sources for secondary research are categorised as.
-         Internet
-         Journals/newspapers
-         Magazines
-         Books
-         Media (TV, News, academic programs)
Explanation
Questionnaire:
            Questionnaire is an important type of primary research. It’s one of the best gadgets used to attempt market research. Normally, questionnaire is a sequence of organised questions related to a particular product or area of business that may handed to respondent to get information. This type of primary research is accompanied only when the interviews has shortage of time. So, the researcher just creates a questionnaire to pass it to concerned person to carry out research.
According to Brown (2001);”questionnaires are many written instruments that present respondent with a series of questions or statements to which they are to react either by writing out their answers or selecting form among existing answers”.
Interviews:
            Interview is one of the best ways to gather information directly by interviewing people related to research. By utilizing this method, researchers start their research by interviewing customers and employees related to the business in which they are carrying out their research. Interview may be short or long depending upon the availability of the interviewed person.
There are different types of interviews. Like for example;
-          Face to face interviews
-          Postal interviews
-          Telephonic interviews
-          Online interviews (video or audio conferencing)
Above all, face to face interview is one of the best ways of gathering primary data.
“A Customers interview is a conversation with customers and use of projects deliverables to define requirements and needs. Interviews are techniques for one-on-one uses needs assessments”.
                                                (Kendrick (2000)) The project management 2000 Edition
In this type of primary research, different face to face interviews and more than 50 people were interviewed on different areas on London as well as in college.
P 13
Presentation file is attatched with this folder.

















References:
Books:
ü  How to Be an Even Better Manager: A Complete A-Z of Proven Techniques and...
ü  By Michael Armstrong
ü  TIME MANAGEMENT
By Dr. Donald E. Wetmore 

ü  Ashton, D., Green, F. (1996) Education, Training and the Global Economy, Edward Elgar, Cheltenham.
ü  Aspin, D.N., Chapman, J.D. (1997) The School, the Community and Lifelong Learning, Cassell, London.
ü  Bourdieu, P., (1986) "The Forms of Capital" in J. E. Richardson (ed.) Handbook of Theory of Research for the Sociology of Education, translated by R. Nice, Greenwood Press, Paris.
ü  Braverman, H. (1976) Labor and Monopoly Capital: the degradation of work in the twentieth century, Monthly Review, New York.
ü  Castells, M. (1996) The Rise of the Network Society, Blackwell, Oxford.

Online references;

Thursday, 1 December 2011

How to create virus in 20 seconds?


Classes in C++


class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions.

An object is an instantiation of a class. In terms of variables, a class would be the type, and an object would be the variable.

Classes are generally declared using the keyword class, with the following format:

class class_name {
  access_specifier_1:
    member1;
  access_specifier_2:
    member2;
  ...
  } object_names;

Where class_name is a valid identifier for the class, object_names is an optional list of names for objects of this class. The body of the declaration can contain members, that can be either data or function declarations, and optionally access specifiers.

All is very similar to the declaration on data structures, except that we can now include also functions and members, but also this new thing called access specifier. An access specifier is one of the following three keywords: privatepublic or protected. These specifiers modify the access rights that the members following them acquire:

  • private members of a class are accessible only from within other members of the same class or from their friends.
  • protected members are accessible from members of their same class and from their friends, but also from members of their derived classes.
  • Finally, public members are accessible from anywhere where the object is visible.

By default, all members of a class declared with the class keyword have private access for all its members. Therefore, any member that is declared before one other class specifier automatically has private access. For example:

1
2
3
4
5
6
class CRectangle {
    int x, y;
  public:
    void set_values (int,int);
    int area (void);
  } rect;


Declares a class (i.e., a type) called CRectangle and an object (i.e., a variable) of this class called rect. This class contains four members: two data members of type int (member x and member y) with private access (because private is the default access level) and two member functions with public access: set_values() and area(), of which for now we have only included their declaration, not their definition.

Notice the difference between the class name and the object name: In the previous example, CRectangle was the class name (i.e., the type), whereas rect was an object of typeCRectangle. It is the same relationship int and a have in the following declaration:

 
int a;


where int is the type name (the class) and a is the variable name (the object).

After the previous declarations of CRectangle and rect, we can refer within the body of the program to any of the public members of the object rect as if they were normal functions or normal variables, just by putting the object's name followed by a dot (.) and then the name of the member. All very similar to what we did with plain data structures before. For example:

1
2
rect.set_values (3,4);
myarea = rect.area(); 


The only members of rect that we cannot access from the body of our program outside the class are x and y, since they have private access and they can only be referred from within other members of that same class.

Here is the complete example of class CRectangle:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// classes example
#include <iostream>
using namespace std;

class CRectangle {
    int x, y;
  public:
    void set_values (int,int);
    int area () {return (x*y);}
};

void CRectangle::set_values (int a, int b) {
  x = a;
  y = b;
}

int main () {
  CRectangle rect;
  rect.set_values (3,4);
  cout << "area: " << rect.area();
  return 0;
}
area: 12


The most important new thing in this code is the operator of scope (::, two colons) included in the definition of set_values(). It is used to define a member of a class from outside the class definition itself.

You may notice that the definition of the member function area() has been included directly within the definition of the CRectangle class given its extreme simplicity, whereasset_values() has only its prototype declared within the class, but its definition is outside it. In this outside definition, we must use the operator of scope (::) to specify that we are defining a function that is a member of the class CRectangle and not a regular global function.

The scope operator (::) specifies the class to which the member being declared belongs, granting exactly the same scope properties as if this function definition was directly included within the class definition. For example, in the function set_values() of the previous code, we have been able to use the variables x and y, which are private members of classCRectangle, which means they are only accessible from other members of their class.

The only difference between defining a class member function completely within its class or to include only the prototype and later its definition, is that in the first case the function will automatically be considered an inline member function by the compiler, while in the second it will be a normal (not-inline) class member function, which in fact supposes no difference in behavior.

Members x and y have private access (remember that if nothing else is said, all members of a class defined with keyword class have private access). By declaring them private we deny access to them from anywhere outside the class. This makes sense, since we have already defined a member function to set values for those members within the object: the member function set_values(). Therefore, the rest of the program does not need to have direct access to them. Perhaps in a so simple example as this, it is difficult to see any utility in protecting those two variables, but in greater projects it may be very important that values cannot be modified in an unexpected way (unexpected from the point of view of the object).

One of the greater advantages of a class is that, as any other type, we can declare several objects of it. For example, following with the previous example of class CRectangle, we could have declared the object rectb in addition to the object rect:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// example: one class, two objects
#include <iostream>
using namespace std;

class CRectangle {
    int x, y;
  public:
    void set_values (int,int);
    int area () {return (x*y);}
};

void CRectangle::set_values (int a, int b) {
  x = a;
  y = b;
}

int main () {
  CRectangle rect, rectb;
  rect.set_values (3,4);
  rectb.set_values (5,6);
  cout << "rect area: " << rect.area() << endl;
  cout << "rectb area: " << rectb.area() << endl;
  return 0;
}
rect area: 12
rectb area: 30  


In this concrete case, the class (type of the objects) to which we are talking about is CRectangle, of which there are two instances or objects: rect and rectb. Each one of them has its own member variables and member functions.

Notice that the call to rect.area() does not give the same result as the call to rectb.area(). This is because each object of class CRectangle has its own variables x and y, as they, in some way, have also their own function members set_value() and area() that each uses its object's own variables to operate.

That is the basic concept of object-oriented programming: Data and functions are both members of the object. We no longer use sets of global variables that we pass from one function to another as parameters, but instead we handle objects that have their own data and functions embedded as members. Notice that we have not had to give any parameters in any of the calls to rect.area or rectb.area. Those member functions directly used the data members of their respective objects rect and rectb.

Constructors and destructors

Objects generally need to initialize variables or assign dynamic memory during their process of creation to become operative and to avoid returning unexpected values during their execution. For example, what would happen if in the previous example we called the member function area() before having called function set_values()? Probably we would have gotten an undetermined result since the members x and y would have never been assigned a value.

In order to avoid that, a class can include a special function called constructor, which is automatically called whenever a new object of this class is created. This constructor function must have the same name as the class, and cannot have any return type; not even void.

We are going to implement CRectangle including a constructor:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// example: class constructor
#include <iostream>
using namespace std;

class CRectangle {
    int width, height;
  public:
    CRectangle (int,int);
    int area () {return (width*height);}
};

CRectangle::CRectangle (int a, int b) {
  width = a;
  height = b;
}

int main () {
  CRectangle rect (3,4);
  CRectangle rectb (5,6);
  cout << "rect area: " << rect.area() << endl;
  cout << "rectb area: " << rectb.area() << endl;
  return 0;
}
rect area: 12
rectb area: 30  


As you can see, the result of this example is identical to the previous one. But now we have removed the member function set_values(), and have included instead a constructor that performs a similar action: it initializes the values of width and height with the parameters that are passed to it.

Notice how these arguments are passed to the constructor at the moment at which the objects of this class are created:

1
2
CRectangle rect (3,4);
CRectangle rectb (5,6);


Constructors cannot be called explicitly as if they were regular member functions. They are only executed when a new object of that class is created.

You can also see how neither the constructor prototype declaration (within the class) nor the latter constructor definition include a return value; not even void.

The destructor fulfills the opposite functionality. It is automatically called when an object is destroyed, either because its scope of existence has finished (for example, if it was defined as a local object within a function and the function ends) or because it is an object dynamically assigned and it is released using the operator delete.

The destructor must have the same name as the class, but preceded with a tilde sign (~) and it must also return no value.

The use of destructors is especially suitable when an object assigns dynamic memory during its lifetime and at the moment of being destroyed we want to release the memory that the object was allocated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// example on constructors and destructors
#include <iostream>
using namespace std;

class CRectangle {
    int *width, *height;
  public:
    CRectangle (int,int);
    ~CRectangle ();
    int area () {return (*width * *height);}
};

CRectangle::CRectangle (int a, int b) {
  width = new int;
  height = new int;
  *width = a;
  *height = b;
}

CRectangle::~CRectangle () {
  delete width;
  delete height;
}

int main () {
  CRectangle rect (3,4), rectb (5,6);
  cout << "rect area: " << rect.area() << endl;
  cout << "rectb area: " << rectb.area() << endl;
  return 0;
}
rect area: 12
rectb area: 30  


Overloading Constructors

Like any other function, a constructor can also be overloaded with more than one function that have the same name but different types or number of parameters. Remember that for overloaded functions the compiler will call the one whose parameters match the arguments used in the function call. In the case of constructors, which are automatically called when an object is created, the one executed is the one that matches the arguments passed on the object declaration:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// overloading class constructors
#include <iostream>
using namespace std;

class CRectangle {
    int width, height;
  public:
    CRectangle ();
    CRectangle (int,int);
    int area (void) {return (width*height);}
};

CRectangle::CRectangle () {
  width = 5;
  height = 5;
}

CRectangle::CRectangle (int a, int b) {
  width = a;
  height = b;
}

int main () {
  CRectangle rect (3,4);
  CRectangle rectb;
  cout << "rect area: " << rect.area() << endl;
  cout << "rectb area: " << rectb.area() << endl;
  return 0;
}
rect area: 12
rectb area: 25  


In this case, rectb was declared without any arguments, so it has been initialized with the constructor that has no parameters, which initializes both width and height with a value of 5.

Important: Notice how if we declare a new object and we want to use its default constructor (the one without parameters), we do not include parentheses ():

1
2
CRectangle rectb;   // right
CRectangle rectb(); // wrong! 


Default constructor

If you do not declare any constructors in a class definition, the compiler assumes the class to have a default constructor with no arguments. Therefore, after declaring a class like this one:

1
2
3
4
5
class CExample {
  public:
    int a,b,c;
    void multiply (int n, int m) { a=n; b=m; c=a*b; }
  };


The compiler assumes that CExample has a default constructor, so you can declare objects of this class by simply declaring them without any arguments:

 
CExample ex;


But as soon as you declare your own constructor for a class, the compiler no longer provides an implicit default constructor. So you have to declare all objects of that class according to the constructor prototypes you defined for the class:

1
2
3
4
5
6
class CExample {
  public:
    int a,b,c;
    CExample (int n, int m) { a=n; b=m; };
    void multiply () { c=a*b; };
  };


Here we have declared a constructor that takes two parameters of type int. Therefore the following object declaration would be correct:

 
CExample ex (2,3);

But,
 
CExample ex;


Would not be correct, since we have declared the class to have an explicit constructor, thus replacing the default constructor.

But the compiler not only creates a default constructor for you if you do not specify your own. It provides three special member functions in total that are implicitly declared if you do not declare your own. These are the copy constructor, the copy assignment operator, and the default destructor.

The copy constructor and the copy assignment operator copy all the data contained in another object to the data members of the current object. For CExample, the copy constructor implicitly declared by the compiler would be something similar to:

1
2
3
CExample::CExample (const CExample& rv) {
  a=rv.a;  b=rv.b;  c=rv.c;
  }


Therefore, the two following object declarations would be correct:

1
2
CExample ex (2,3);
CExample ex2 (ex);   // copy constructor (data copied from ex) 


Pointers to classes

It is perfectly valid to create pointers that point to classes. We simply have to consider that once declared, a class becomes a valid type, so we can use the class name as the type for the pointer. For example:

 
CRectangle * prect;


is a pointer to an object of class CRectangle.

As it happened with data structures, in order to refer directly to a member of an object pointed by a pointer we can use the arrow operator (->) of indirection. Here is an example with some possible combinations:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// pointer to classes example
#include <iostream>
using namespace std;

class CRectangle {
    int width, height;
  public:
    void set_values (int, int);
    int area (void) {return (width * height);}
};

void CRectangle::set_values (int a, int b) {
  width = a;
  height = b;
}

int main () {
  CRectangle a, *b, *c;
  CRectangle * d = new CRectangle[2];
  b= new CRectangle;
  c= &a;
  a.set_values (1,2);
  b->set_values (3,4);
  d->set_values (5,6);
  d[1].set_values (7,8);
  cout << "a area: " << a.area() << endl;
  cout << "*b area: " << b->area() << endl;
  cout << "*c area: " << c->area() << endl;
  cout << "d[0] area: " << d[0].area() << endl;
  cout << "d[1] area: " << d[1].area() << endl;
  delete[] d;
  delete b;
  return 0;
}
a area: 2
*b area: 12
*c area: 2
d[0] area: 30
d[1] area: 56


Next you have a summary on how can you read some pointer and class operators (*&.->[ ]) that appear in the previous example:

expressioncan be read as
*xpointed by x
&xaddress of x
x.ymember y of object x
x->ymember y of object pointed by x
(*x).ymember y of object pointed by x (equivalent to the previous one)
x[0]first object pointed by x
x[1]second object pointed by x
x[n](n+1)th object pointed by x

Be sure that you understand the logic under all of these expressions before proceeding with the next sections. If you have doubts, read again this section and/or consult the previous sections about pointers and data structures.

Classes defined with struct and union

Classes can be defined not only with keyword class, but also with keywords struct and union.

The concepts of class and data structure are so similar that both keywords (struct and class) can be used in C++ to declare classes (i.e. structs can also have function members in C++, not only data members). The only difference between both is that members of classes declared with the keyword struct have public access by default, while members of classes declared with the keyword class have private access. For all other purposes both keywords are equivalent.

The concept of unions is different from that of classes declared with struct and class, since unions only store one data member at a time, but nevertheless they are also classes and can thus also hold function members. The default access in union classes is public.
Index
Index