project in electronics in huwai

Upload: mmujeeburrehman

Post on 08-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    1/65

    A

    PRACTICAL TRAINING REPORT

    ON

    Project Student Management

    AT

    APTECH COMPUTER CENTRE, Abohar

    Submitted for the partial fulfillment for the award of Diploma

    of Engineering (Electronics & Communication)

    Submitted to: Submitted by:

    Mrs. RANJIT KAUR Mani shankar

    Coordinator 2nd Year (3rd Semester)

    electronics & communication

    DEPARTMENT OF ELECTRONICS AND COMMUNICATION

    SANT LONGOWAL INSTITUTE OF ENGINEERING &

    TECHNOLOGY, LONGOWAL

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    2/65

    ACKNOWLEDGEMENT

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    3/65

    This Training has been done with tedious efforts and consistent

    dedication. I hope this training will be appreciated. Now it time to

    thank all the people who helped me directly or indirectly to

    achieve my goal. The people who always keep on guiding me likesign boards and did never expect anything from me. But after the

    completion of this project, I would like to pay my sincere thanks

    to all who apparently or non-apparently helped me in developing

    this project and surely deserve it.

    No work can be perfect without the ample guidance. I

    would like to express my deep gratitude and heartiest thanks to

    our Director Dr.(Mrs) S.K.Panday and the Training and

    Placement Officer who infused us with the spirit to work upon

    challenging field, which has its inception such a time when there

    is a need for new orientation.

    I'm thankful to the CENTER MANAGER of APTECH

    Computer Mr. Baljinder Phutela for showing trust in me and

    providing me chance to work in his company. Also I'm thankful to

    the Mr. Kamal Suresh (Technical Instructor) who helped

    me, guided me and provided me various valuable suggestions

    which will be always helpful for me.

    MANI SHANKAR

    II Year DIPLOMA (III Semester)

    ELECTRONICS & COMMUNICATION

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    4/65

    PREFACE

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    5/65

    Practical training is an important part of the engineering. During

    practical training, we learn how work is actually done, in the real

    sense. Beside this we also learn code of conduct as well as how

    to behave in the working environment. After getting training weget accustom to the working environment. These things are

    important part and we learn to apply them in our professional

    life.

    In today information computer are being used in every

    occupation. They are being used by the people of all age and

    profession in there work, As well as in there leisure. This new

    social revolution has change the basic concept of computing.

    Computing, in todays information age is no more limited to

    computer programmers and computer engineer it has become

    and activity of common man. so one should know how to

    program a computer.

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    6/65

    CONTENTS

    PREFACE

    ACKNOWLEDGEMENT

    INTRODUCTION 1

    STEPS IN RUNNING A C++ PROGRAM 3

    DISADVANTAGES 4

    CONSTANT,VARIABLES AND DATA TYPES 5

    OPERATORS ANDEXPRESSIONS 8

    DATA I/P AND O/P 10

    CONTROL FLOW STATEMENTS 11

    FUNCTIONS 16

    ARRAY 19

    STRUCTURE 20

    UNION 20

    OOPS 21

    CHARACTERISTICS OF LOOPS 24

    CONSTRUCTORS AND DESTRUCTORS 25

    FRIEND FUNCTIONS 26

    OPERATOR OVERLOADING 26

    INHERITANCE 28

    FILE HANDLING 35

    APPLICATIONS 39

    COADING OF PROJECT 40

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    7/65

    Introduction to programming languages(C++)

    A program is a set of instructions which tells a computer about

    which data to be input and which to output.

    Many different languages are used to program a computer. The

    most basic of these languages is machine language, which is a

    collection of instructions that controls the computers internal

    circuitry. However, very few computer programs are actually

    written in machine language for two reasons:

    1. Machine language is very difficult to work with.

    2. Most computers have their own unique instruction sets so a

    machine language program written for one type of computer

    cannot be run on another type of computer without being

    changed.

    Usually a computer program is written in a high-level language for

    two reasons:

    1. Instructions of high-level language matches with human

    languages.

    2. The same general programming rules apply to all computers so

    a program written in a high-level language can generally be run

    on many different with a little or no alteration.

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    8/65

    A program written in high-level language must, however, be

    translated into machine language before it can be executed. The

    original high-level language program is called the source program

    and the resulting machine-language program is called object

    program, while the process of translation is known as compilation

    or interpretation depending on how it is carried out.

    1. Compilers translate the entire program into machine language

    before executing any of the instructions.

    2. Interpreters proceed through a program by translating and then

    executing single instructions.

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    9/65

    Steps in running a c/c++ program

    Executing a program involves following steps:

    1. Creating the program:-

    The first step includes simply typing in the program in any text

    editor like edit, notepad or VI editor. The program file must

    however be saved with the extension .c. Thus a C program file is

    always saved as filename.c.

    2. Compiling the program:-

    It involves translating the source code to the object code. This step

    is implemented differently in different operating steps.

    3. Linking the program:-

    It is the process of putting together other program files and

    functions that are required by the program.

    e.g. sqrt() function, the object code of this function should be

    brought from the math library and linked to the main() program.

    To compile the program welcome.cpp in MSDOS, we must type

    MSC welcome.cpp.

    On doing so, the object code is stored in a file named welcome.obj.

    The linking is done by command

    LINK welcome.obj

    Which generates the executable code in a file named welcome.exe.

    Finally to execute the program welcome.c, we have to simply type

    the following at the command prompt. Welcome

    Advantages of C/C++:

    1. Machine independence: There codes can be compiled on

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    10/65

    different machines and they produce the same output when

    executed.

    2. Economy of expression: They are compact and coherent

    programming languages. The codes are very powerful so that a

    small length of codes can perform complex tasks.

    3. Data structures: There are several ways to store data on C/C+

    +, which allows easy access of data.

    4. Operator richness: They support a wide range of operators to

    handle arithmetic and logical calculations.

    Disadvantages of C/C++:

    1. Difficult to debug: They give a lot of freedom to the developer,

    but it is a bit difficult for any new user to find out where is the

    error in the program.

    2. Loosely syntaxed: They allow a lot of freedom in coding. We

    can give end of statement symbols (;), blank lines, white spaces

    anywhere we want in the program. There is no fixed place to

    start or end a line. This can give rise to codes that are difficult to

    understand by reading.

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    11/65

    Constants, Variables and Data types

    C++ character set

    Following are the valid alphabets, numbers and special symbols

    allowed in c:

    Alphabets A, B, C, Y, Z

    a, b, c., y, z

    Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

    Special symbols ~! @ # % ^ & * ( ) _ - +

    | \ { } [ ] : ; < > , . ? / =

    C++ keywords

    The words whose meaning has already been explained to the c

    compiler are called keywords.

    There are 32 keywords in C.C++ has all these but some extra also.

    They appear in white color on programming screen.

    Few important keywords are:

    Auto, double, int, float, struct, class etc.

    Data types

    The important data types used in C++ are:

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    12/65

    Char:

    It holds individual characters and occupies 1 byte.

    Int:

    It requires 2 bytes and range of storage is -32767 to +32768, it

    stores only the whole integer numbers.

    Float:

    It can hold decimal numbers also; it takes 4 bytes.It can give up to

    6 digits after decimal.

    Double:

    It also stores the decimal values but it can give up to 15 digits after

    decimal. It requires 8 bytes.

    We can also add some modifiers in front of these data types so that

    we can alter their range according to our need. Important modifiers

    are short, long, signed, unsigned.

    Constants

    Like identifiers or variables we can have constants of the type int,

    float, and char.Integer constants:

    They are simply the integer valued numbers. They are sequence of

    digits taken between 0 and 9. Zero cannot be the starting digit.

    They have a positive or a negative sign in their front. They can be

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    13/65

    represented as decimal, octal and hexadecimal.

    Floating point constant:

    A floating point constant is a decimal number that contains either

    decimal or an exponent form. It is a sequence of digits having a

    decimal in between. It can also have a positive or a negative sign in

    front. Its general exponential form is: mantissa E exponent.

    Character constant:

    It is simply a single character. It is always defined inside single

    quotation (a). We can also write 4 but it is different from 4

    because in this case 4 is represented by its ASCII(American

    standard code for information interchange) value which is different

    for every character being used in c.

    String constant:

    A string is simply a sequence of characters. It is represented by

    putting double quotation (welcome). The compiler puts a null

    (\0) character at the end of every string.

    Symbolic constants (macros):

    If we have to use a value 3.142 (value of constant pi) many times

    then it will be very time consuming to write and also understanding

    about for what purpose the value is written, for this we can use

    macros and define them in the beginning of the program.e.g. we can write #define pi 3.142

    Now we can directly write pi at all places where we have written

    3.142. In this way we can improve readability of the code and also

    easy maintenance of the code.

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    14/65

    Declaration of variables:

    Syntax: data-type var1, var2, var3 varn;

    Where data-type tells the compiler about whether it is a character,

    integer, or a decimal number. e.g. int n; float interest; char x;

    Operators and Expressions

    An operator is a symbol that tells the compiler to perform certain

    mathematical and logical operations. The data items that operators

    act upon are called as operands. The operators which need one

    operand at a time are called unary operators whereas those using

    two operands are called binary operators.

    C operators can be classified as:

    1. Arithmetic operators.

    2. Relational operators.

    3. Logical operators.

    4. Assignment operators.

    5. Conditional operators.

    6. Special operators.

    C++ has all these operators but also some extra operators. These

    are:1. Stream input/output operators()

    2. scope Resolution operators(::)

    3. line feed operators(endl)

    4. field width operators(setw)

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    15/65

    5. memory allocation operators(new)

    6. memory deallocation operators(delete)

    The chart below shows the operators with the order of precedence:

    Operators name Operators

    1. Unary operator - ++ -- !

    2. Arithmetic multiply * / %

    divide, modulus

    3. Arithmetic add, + -

    Subtract

    4. Relational operator >=

    5. Equality operators == !=

    6. Logical and &&

    7. Logical OR ||

    8. Conditional operator ?:

    9. Assignment operator = += -= *= /= %=

    Special operators are sizeofoperator, pointer operators (& and *)

    and member selection operators (. and ->).

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    16/65

    Data input and output

    While writing the program we need input/output functions cout or

    cin, for calling these functions we have to include some header files

    like stdio.h and iostream.h which are given in two ways:

    #include this tells the preprocessor to search for a file

    named stdio.h and places it in the program. tells to look in the

    include directory for the file stdio.h. Whereas stdio.h tells the

    preprocessor to look in the current directory.

    Character input and output:

    Getchar(): It is the most basic way of reading a character

    variable=getchar()

    By writing this we can enter any amount of characters that we want

    but only the first character typed will be stored. The similar

    functions to this are getch() and getche().

    Putchar (): It is a complementary function to getchar as it is used

    to display a single character putchar(variable).

    Formatted input and output:

    The two functions getchar and putchar are unformatted I/O

    functions whereas cout and cin are the formatted I/O functions.

    The difference between two categories is that the formatted

    functions allow us to input by using keyboard and get output on the

    screen according to our requirements.

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    17/65

    Control flow statements in C++

    These statements help in decision making and repetition of various

    instructions.

    1. if statement: it is the general decision making statement.

    Syntax: if(expression)

    program statement;

    The expression is evaluated if it is TRUE (i.e. non-zero value)

    otherwise the compiler will skip the statement.

    e.g. if (5>3)

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    18/65

    Syntax: if(expression)

    {

    if(expression)

    statement;

    else

    statement;

    }

    else

    {

    if(expression)

    statement;

    }

    The above used nested statements can be used as a regular trend

    which is named as else-if statement block.

    Syntax: if(expression 1)

    statement1;

    else if(expression 2)

    statement2;

    else if(expression 3)

    statement3;

    ..

    .else

    statementn;

    2. While statement: the while statement is used for repetition. The

    working of while statement is as follows:

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    19/65

    The expression is evaluated first. If it evaluates to true then the

    statements are executed and the increments occur and the

    expression is evaluated again. This cycle continues until the

    expression evaluates to false.

    Syntax: while(expression)

    {

    statement;

    increment/decrement;

    }

    e.g. #include

    void main()

    {

    int i= 0;

    while(i

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    20/65

    Statement block;

    The three parts inside loop can be omitted singly.

    The init expression tells about the initialization of the variable.

    Second statement tells the condition which has to be true for the

    loop to work.

    Third statement tells about the increment or decrement of the

    variable.

    e.g. #include

    void main()

    {

    int i, sum;

    sum=0;

    for(i=0; i

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    21/65

    The difference between while and do-while is that the do-while

    loop works once even if the condition becomes false in the

    beginning.

    e.g. #include

    void main()

    {

    int i= 1, sum;

    Sum=0;

    do

    sum = sum + i;

    while (i

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    22/65

    default: statement;

    }

    The expression inside the switch statement tells the compiler

    which case first to be evaluated. When the compiler reaches the

    mentioned case it evaluates the instructions but doesnt stop

    after that, it also evaluates the coming statements also, therefore

    to remove this we use breakstatement at the end of each case

    which automatically brings the compiler out of the case after

    compiling it.

    6. break: It allows us to exit from the while loop or the for loop.

    As soon as the break statement comes the compiler comes out of

    the loop.

    7. continue: It allows us to continue the execution of the loop from

    the beginning and leaving all the statements following it i.e. as

    soon as the continue statement is encountered the loop goes to

    its starting point.

    Functions

    A function is a set of instructions which perform a particular task.

    In c language it can be a combination of set of different small

    functions which perform different task. There are two types of

    functions:

    1. Library functions.

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    23/65

    2. User defined functions.

    Library functions are those functions which are already defined

    for the compiler. e.g. printf(), scanf() functions are already defined

    in the C library in stdio.h header file.

    User defined functions are those which are created by a

    programmer for a particular task. The steps involved in creating and

    using a user defined function are as following:

    1. Declaring a function prototype.

    2. Defining the function.

    3. Calling the function.

    e.g. #include

    welcome()

    {

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    24/65

    the function welcome() it automatically goes out of main() and

    firstly execute welcome() then the further statements of main().

    Passing arguments to a function

    It can be done by two processes:

    1. Call by value process.

    2. Call by reference process.

    When we pass the value of the variables as such to a function the

    process is known as call by value. e.g.

    Recursive functions

    A function that calls itself is known as the recursive function. This

    concept can be used as a replacement of looping. e.g.

    #include

    main()

    {

    int num;

    coutnum;

    factorial= fact (num);

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    25/65

    if(n== 1)

    return (1);

    else

    return (n* factorial (n-1));

    }

    The above program regularly calls the function and returns the

    value of factorial.

    Arrays

    It is a collection of the variables that have same name and data

    type.

    General definition of single dimensional array:

    Storage-class data-type array[expression]

    e.g. int x [100]; char name[30];

    Different elements of array can be represented as x[0], x[1], x[2],

    x[3], x[n].

    Initialization of an array:

    Storage-class data-type array[expression]= {value1, value2

    valuen}

    It is our choice to give the array size during initializing, because a

    blank already sets the space for the entered values.

    e.g. int y[] = {1, 2, 3, 4, 5};

    char y[]= COMPUTER;

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    26/65

    Structures

    A structure is a collection of one or more variables of different type

    grouped together having a single name.

    General format:

    struct tag-name

    {

    data-type member1;

    data-type member2;

    ..

    data-type member n;

    } variable1, variable2 variable n;

    Accessing structure elements:

    The structure variable can be accessed by using dot (.) operator or

    arrow (->) operator.

    We write variable.member to access the variable using dot (.)

    operator, for using arrow operator we use the pointers.

    The dot operator is also known as member operator. It has the

    highest precedence over all the unary and binary operators.

    Unions

    Unions is just same as the structure definition, this is also used to

    group together same variables.

    The difference between structure and union is that in union all the

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    27/65

    variables are given same memory location whereas in structure

    each variable is given separate memory, therefore the union is used

    to save the wastage of memory.

    storage-class union tag-name

    {

    data-type member1;

    data-type member2;

    .

    data-type membern;

    } variable1, variable2 variablen;

    OOPS

    Both the programming languages c & c++ are related to each other.

    In real sense we can directly say that c++ language is extension

    (increment) of c language by observing the ++ operator which

    tells the incrementation by one in c language.

    All the above written topics are used in nearly the same way as in C

    language.

    C++ contains the new concept of OOPS (object oriented

    programming), rest of the conceptual portion of c++ is same as that

    of c language. The small difference between them is of keywords

    e.g. c++ uses cout and cin as their input and output functions

    whereas c uses printf and scanf on the same place.

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    28/65

    OOPS concept

    Object oriented programming is a conceptual approach. Its main

    features are:

    1. Data abstraction.

    2. Data hiding and encapsulation.

    3. Polymorphism.

    4. Inheritance.

    The most important feature of C++ is the data abstraction called

    Class.

    A class description consists of two parts:

    (a) class definition of the components (data members and member

    functions).

    (b) class implementation or definition of member functions.

    e.g. class person

    {

    private:

    char name[20];

    int age;

    double height;

    public:

    void getdata(void);

    void setdata(char *string, int a, double h);

    void showdata(void);

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    29/65

    };

    The data members and member functions are defined in three types

    of accessibility options.

    1. private: The private data members and member functions are

    accessible only within the class description. They are hidden

    from rest of program, therefore it comes under the concept of

    data hiding.

    2. public: Those which can be used outside of the class definition.

    They act as a route between private members and rest of the

    program.

    3. protected: It is helpful in inheritance, any member declared as

    protected is accessible by the member function within its class

    and any immediately derived class, cannot be accessed by

    outside function of these two classes.

    Classes and objects

    A class description like a structure description will not reserve

    space in memory. When actual data objects are created they reserve

    the pace for individual data members.

    Person p1, p2;

    name name.age.. age

    height.. height

    p1 p2

    The member functions can be accessed as:

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    30/65

    p1.getdata();

    p2.setdata();

    p3.showdata();

    The setdata(), getdata(), and the showdata(), functions of class

    person are unique copy for different objects.

    We can separate the program in two segments one containing the

    class with the description of data members and member functions,

    and the second part containing the main() function.

    The first part is stored as file.h and will be directly used in the

    second segment as #includefile.h.

    Characteristics of OOPS:

    1. In oop data and a function that update on that data are combined

    into a single unit known as object.

    2. A class is description of a number of similar objects.

    3. Inheritance, each sub-class share common characteristics with

    the class from which it is derived.

    4. Reusability: A particular class is created and distributed to

    other programmer for use in their other programs.

    5. Polymorphism: One thing with several forms known as

    overloading. The processes are known as operator overloading

    and function overloading.

    Operator overloading: e.g. a + operator can be made useful toadd two different strings.

    Function overloading: The function with same name but with

    different parameters.

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    31/65

    Add(int a, int b);

    Add(int a, float b);

    6. Data encapsulation: it includes the concept of building data and

    function together.

    7. Data hiding: protecting data from access by unauthorized

    function.

    8. Data abstraction: it is the concept of simplifying the real world

    concept into its essential elements representing essential features

    without including background details.

    Constructors

    We define the values to the variables of functions by creating a new

    function, to reduce this problem and to initialize the variable at the

    time of calling of function in main() we use the concept of

    constructors.

    Constructors have the same name as that of class name.

    Two ways to initialize a constructor inside main():

    1. person p= person(ram,40,5.7);

    2. person p(ram,40,5.7);

    Each and every time a function is called the constructor will be

    automatically be called, therefore to reduce this effect and made use

    of the constructor required number of time we use default

    constructors. It is a blank function.

    Destructor function

    When an object is created it calls the constructor function.

    whenever a program exits all its objects are expired, during this

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    32/65

    process the program calls a function called destructor function.

    The destructor function helps undo the work of the constructor. i.e.

    if constructor uses new operator then the destructor uses delete

    operator.

    The destructor has the same name as that of class followed by a

    tilde(~) sign. It doesnot have any return type. e.g. ~person(void).

    Friends and operator overloading(POLYMORPHISM)

    A friend function is a member function that are useful in accessing

    the private data members. To invoke a friend function objects are

    not required. Objects are passed as arguments to the friend

    function.

    Operator overloading

    C++ provides a rich collection of various operators, it enables an

    operator to exhibit more than one operation, e.g. a simple addition

    operator(+) can be used to add two numbers can be made to add

    two strings.

    Rules of overloading:

    1. . .* :: ?: sizeof # = () [] -> are the operators that cannot beoverloaded.

    2. operators already predefined in c++ compiler can be only

    overloaded.

    3. operator cannot change operator templates e.g. the increment

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    33/65

    operator is used only as unary operators, it cannot be used as a

    binary operator.

    4. overloading an operator doesnot change its basic meaning e.g.

    the + operator cannot be overloaded to subtract two objects.

    Function overloading

    Same function name can be used for different purposes.

    Class a

    {

    Public:

    Void add()

    {

    couta>>b;

    c=a+b;

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    34/65

    {

    clrscr();

    a z;

    z.add();

    z.add(8.4);}

    Inheritance

    The formation of derived classes out of the base class and using the

    visibility options according to our requirement is known as

    inheritance.

    The definition of derived class is given by:

    Class derive

    d::public/private/protected base

    {

    public:

    void display(void);

    };

    The way in which a derived class is being called decide how the

    variables get the accessibility. To know the accessibility we use the

    chart below:

    Base

    class

    visibility

    Public

    derivation

    Private

    derivation

    Protected

    derivation

    Private Not

    inherited

    Not

    inherited

    Not

    inherited

    Protected Protected Private Protected

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    35/65

    Public Public Private Protected

    Types of inheritance:

    1. Single inheritance: it includes forming of a derived class from

    one single class.

    Class father

    {

    private:int age;

    char name[20];

    public:

    void get();

    void show();

    };

    class mother: public father

    {

    private:

    int age;

    char name[20];

    public:

    void get();

    void show();

    };

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    36/65

    2. Multilevel inheritance: The mechanism of deriving a class

    from another derived class.

    Class father

    {

    private:

    int age;

    char name[20];

    public:

    void get();

    void show();

    };

    class mother: public father

    {

    private:

    int age;

    char name[20];

    public:

    void get();

    void show();

    };class daughter:public mother

    {

    private:

    int std;

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    37/65

    char name[20];

    public:

    void get();

    void show();

    };

    3. Multiple inheritance: when a derived class is made by using

    two or more base classes.

    Class father

    {

    private:

    int age;

    char name[20];

    public:

    void get();

    void show();

    };

    class mother

    {

    private:

    int age;char name[20];

    public:

    void get();

    void show();

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    38/65

    };

    class daughter:public father,public mother

    {

    private:

    int std;

    char name[20];

    public:

    void get();

    void show();

    };

    4. Hierarchical inheritance: if one class may be inherited by more

    than one class.

    Class father

    {

    private:

    int age;

    char name[20];

    public:

    void get();

    void show();};

    class daughter:public father

    {

    private:

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    39/65

    int std;

    char name[20];

    public:

    void get();

    void show();

    };

    class son:public father

    {

    private:

    int rollno;

    char name[20];

    public:

    void get();

    void show();

    };

    5. Hybrid inheritance: it is the mixture of multiple and

    hierarchical.

    Class student

    {

    private:

    int rollno;public:

    void get();

    void show();

    };

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    40/65

    class test:public student

    {

    protected:

    float part1, part2;

    public:

    void getm();

    void showm();

    };

    class sports

    {

    protected:

    float score;

    public:

    void gets();

    void shows();

    };

    class result:public test, public sports

    {

    float total;

    public:

    void display();};

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    41/65

    File handling in C++

    Header files

    ifstream, ofstream, and fstream classes are declared in the fstream.h

    file. This file also includes the iostream.h header file.

    String input/output

    Write:

    #include

    void main()

    {

    ofstream outfile(test.txt);

    outfile

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    42/65

    infile.getline(buffer, max);

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    43/65

    }

    }

    Object input and output:

    Write:

    #include

    class person

    {

    private:

    char name[20];

    int age;

    public:

    void getdata();

    {

    coutname;

    coutage;

    }

    };

    void main()

    {person p;

    p.getdata();

    ofstream outfile(person.dat);

    outfile.write(char *)&p,sizeof(p));

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    44/65

    }

    Read:

    #include

    class person

    {

    private:

    char name[20];

    int age;

    public:

    void showdata()

    {

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    45/65

    Applications of C/C++:

    General applications.

    Database systems.

    Spread sheets.

    Graphic packages.

    Word processors.

    Office automation.

    Scientific/engineering applications.

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    46/65

    /************************************************************/

    #include

    #include

    #include

    #include

    #include

    #include

    /************************************************************/

    /************************************************************/

    class personal

    {

    char nm[20],fnm[20],cl[10],add[40],city[15],state[15],phc[10];

    int age,dd,mm,yy;

    float phn,zpcode;

    public:

    int rn;

    void get(void);

    void put(void);

    };

    /************************************************************/

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    47/65

    /************************************************************/

    class marks

    {

    char sb[10][10],gd,ans;

    int m[10],mm[10],ts,tmm,tmo;float av,per;

    public:

    int rn1;

    void get1(void);

    void put1(void);

    void cal(int mm[],int ts,int m[]);

    };

    /************************************************************/

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    48/65

    /************************************************************/

    void personal::get(void)

    {

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    49/65

    cin>>state;

    gotoxy(22,13);

    cin>>zpcode;

    gotoxy(22,14);

    cin>>phc;

    gotoxy(22,15);

    cin>>phn;

    }

    /************************************************************/

    /************************************************************/

    void personal :: put (void)

    {

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    50/65

    /************************************************************/

    void marks::get1(void)

    {

    coutrn1;

    comp(rn1);

    ans='y';

    ts=0;

    for(int i=0;ans=='y';i++)

    {

    ts++;cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    51/65

    /************************************************************/

    /************************************************************/

    void marks::cal(int mm[],int ts,int m[])

    {

    tmm=0;

    tmo=0;

    for(int j=0;j

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    52/65

    /************************************************************/

    /************************************************************/

    void marks::put1(void)

    {

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    53/65

    /************************************************************/

    /************************************************************/

    personal per;

    marks mak;

    ofstream f1;

    ifstream f2;

    fstream f;

    /***********************************************************/

    /***********************************************************/

    void main()

    {

    xyz:

    clrscr();

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    54/65

    switch(e)

    {

    case 1:

    {

    char rep='y';

    while(rep=='y')

    {

    clrscr();

    add();

    cout>rep;

    }

    goto abc;

    }

    case 2:

    {

    clrscr();

    mod();

    goto abc;

    }

    case 3:

    { clrscr();

    del();

    goto abc;

    }

    case 4:

    {

    clrscr();

    search();

    goto abc;

    }case 5:

    {

    clrscr();

    list();

    goto abc;

    }

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    55/65

    case 6:

    {

    clrscr();

    goto xyz;

    }

    default:

    {

    clrscr();

    goto abc;

    }

    };

    }

    case 2:

    { pqr:

    clrscr();

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    56/65

    del1();

    goto pqr;

    }

    case 4:

    {

    clrscr();

    search1();

    goto pqr;

    }

    case 5:

    { clrscr();

    list1();

    goto pqr;

    }

    case 6:

    {

    clrscr();

    goto xyz;

    }

    default:{

    clrscr();

    goto pqr;

    }

    };

    }

    case 3:

    {

    exit(0);

    }default:

    {

    clrscr();

    goto xyz;

    }

    };

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    57/65

    }

    /************************************************************/

    /************************************************************/

    void add (void)

    {

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    58/65

    f.seekg(-sizeof(per),ios::cur);

    f.write((char *)&per,sizeof(per));

    k=1;

    break;

    }

    }

    if(k==0)

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    59/65

    }

    }

    if(k==0)

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    60/65

    rename("new.txt","mi.txt");

    coutans;

    f.close();

    }

    }

    /************************************************************/

    /************************************************************/

    void list (void){

    f2.open("mi.txt");

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    61/65

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    62/65

    }

    }

    /************************************************************/

    /************************************************************/

    void search1(void)

    {

    int c,k;

    f2.open("mi.txt");

    char ans='y';

    while(ans=='y')

    {

    coutc;clrscr();

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    63/65

    /************************************************************/

    void del1 (void)

    {

    int c;

    f1.open("new.txt");

    f2.open("mi.txt");

    char ans='y';

    while(ans=='y')

    {

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    64/65

    /************************************************************/

    void list1 (void)

    {

    f2.open("mi.txt");

    cout

  • 8/7/2019 PROJECT IN ELECTRONICS IN HUWAI

    65/65

    /************************************************************/

    void comp(int rn1)

    {

    f2.open("mi.txt");

    char d;int t=0;

    while(f2.read((char *)&per,sizeof(per)))

    {

    if(per.rn==rn1)

    {

    t=1;

    break;}

    }

    if(t==0)

    {

    cout>d;

    if(d=='y')

    {

    clrscr();add();

    }

    }

    }

    /************************************************************/