C++ -Simple class ( An archived file)

Objectives :

  • Introducing class, using Qunicy 2005 compiler and win 2000 professional.
  • strcpy, wcscpy, _mbscpy
  • Copy a string.
    • char *strcpy( char *strDestination, const char *strSource );
    • wchar_t *wcscpy( wchar_t *strDestination, const wchar_t *strSource );
    • unsigned char *_mbscpy( unsigned char *strDestination, const unsigned char
      *strSource );
  • Routine Required Header Compatibility
    strcpy <string.h> ANSI, Win 95, Win NT
    wcscpy <string.h> or <wchar.h> ANSI, Win 95, Win NT
    _mbscpy <mbstring.h> Win 95, Win NT
  • Defining a Class
  • · Access Modifiers : Public or Private or Protected
    class name // needs keyword class and identifier like "Name"
    // for sanity the class name should start with capital letter
    // although C++ will not object to "Base" or "base"
    { // opening braces
    // scope of the members
    private:
    // visible within the same class
    protected:
    // visible to the same and derived classes
    public:
    //visible to all
    }// closing braces
  • How access Class mmbers
    • Member access operators:
      • – Dot operator (.) for structures and objects
        • Classinstance.ClassObject
      • -Arrow operator (->) for pointers
        – Print member hour of timeObject:
        cout <<mcptr->print();
        clsptr->print2(12);
      • --------------------
        mcptr->print(); is same as
        (mcptr).print()
        -- Parentheses required:
        --* has lower precedence than .

Using Quincy Compiler

code Snippets

//classandobject.cpp
#include <iostream.h>
#include <string.h>
class Employee
{
public:
char name[64];
long eID;
float salary;
//function with scope public
void show_employee(void) //function prototype
{
cout <<endl;
cout << "Name: " << name << endl;
cout << "ID: " << eID << endl;
cout << "salary: " << salary<< endl;
}; // function will end here
};
int main()
{
// class name , class variable(objects)
Employee worker, boss;
//
strcpy(worker.name, "Manas Mukherjee");
worker.eID = 12345;
worker.salary = 65000;
//
strcpy(boss.name, "Dan Smith");
boss.eID = 1007;
boss.salary = 165000;
//
worker.show_employee();
boss.show_employee();
return 0;
}




 

Step : 2 Run time view