MS Rumi. Powered by Blogger.
Showing posts with label Education. Show all posts
Showing posts with label Education. Show all posts

Thursday, 30 October 2014

C++ Project For Novice Programmer Bank Account With Classes

What is Static Variable in c++?

In simple computer codding or in programming, variable that allocated statically called static variable. Static variable saved in memory till program ends . In other words its the variable you define as static and it will store at the same place or location you assign it and it will remain at same place throughout the execution of your whole program.
Static Local Variable
Static Variable in C++
Question Asked in Interview "What is Static?"
Answer:- It is a variable that is declared static in the body of function and it maintains its data or value throughout the function.
Static Variable is declare : static int   totalObject;
Initializing Value, Outside  the class   e.g int Bank :: totalObject=0;  You can check in example below.
Operation: totalObject++; inside the class

What is member Initializer list in c++ and Why need it?

Member intilializer is a constructor used in c++. Instant of using variable inside the constructor here we use it outside the constructor body. Variable are listed after the header of the constructor and it is separated by a colon (:). Every variable is in the form of data member name and parameter  from the main function.
Member Intitializer in C++
Member Intitializer

Example of Member Initializer and Static Variable

#include<iostream.h>
class Bank                        // Class Name
{
    private:                  
        const int password;        // Constant Integer
        char *name;                // Pointer Character For Dynamic Charracter Array
        int amount;                // Simple integer
    public:
        static int totalObject; // Static Integer
        Bank(int pass):password(pass), name(NULL),amount(0) // Member Intilizer For Constant Variable
        {
            totalObject++; // When Constructor will call it will one to variable
            name= new char [20];  // Assigning memory to name
        }
        // Setters.....
        void setName(char *n)    // setter for Name
        {
            name=n;
        }
        void setAmount(int am)  // Setter For Amount
        {
            amount=am;
        }
        // Getters
        char* getName()
        {
            return name;
        }
        int getAmount()
        {
            return amount;
        }
        const int getPassword()
        {
            return password;
        }
        // Function For Transaction
        void Deposit(int DA) // Function To Deposit Amount
        {
            amount=amount+DA;
            cout<<"After you Deposit amount your new balance is:"<<amount<<endl;
        }
        void withDraw(int wd)  // Function to Withdraw and Update Amount
        {
            amount=amount-wd;        // Amount will Here
            cout<<"After Withdraw Your New Amount is:"<<amount<<endl;
        }
      
};
// Intiliazing Static variable
int Bank::totalObject=0;

// Main Function
void main ()
{
    int deposit,witdraw,password,amount;
    char name[20];
    // Entering Data For Account
    cout<<"Enter User Name: ";
    cin>>name;
    cout<<"Enter Pssword For Account: ";
    cin>>password;
    Bank Account(password); // Creating Object and assigning constant value
    Account.setName(name);
    cout<<"Enter Amount For Your ACCOUNT:";
    cin>>amount;
    Account.setAmount(amount);
    cout<<"Enter Amount To Deposit:";
    cin>>deposit;
    Account.Deposit(deposit);
    cout<<"Enter Amount To Widraw:";
    cin>>witdraw;
    Account.withDraw(witdraw);
    // Displaying Account Information
    cout<<"Total Objects In Class::"<<Bank::totalObject<<endl;
    cout<<"****Your Complete Account Information*****"<<endl;
    cout<<"Account Name        ::"<<Account.getName()<<endl;
    cout<<"Account Password  ::"<<Account.getPassword()<<endl;
    cout<<"Amount In Account ::"<<Account.getAmount()<<endl;

}

Output of program

 
C++ Project Foe Beginner
Bank Account

Sunday, 26 October 2014

Interview Question For Association, Composition and Aggregation in OOP

Explanation of  Association, Composition and Aggregation in OOP with examples (C++)

Association

C++ Implementation of Association
It is the relationship between two or more objects, where every objects have its own life cycle and there is no owner of these objects. Let's have an example of association between student and tutor. One student can teach by one tutor, many student can teach by one tutor or many tutor can associate with a single student and also many student associate with many teacher or tutor. Here student and tutor are the objects and both have no owner. They can build and delete independently. Association is represented by a solid line.

Generalization

In object oriented modal some classes may have common characteristic we extract there common feature into new class and inherit original classes from this new class. For example we have two classes Teacher with characteristic name, age, sex, birthday, class, salary and job title  Student with characteristic name, age, sex, birthday, class, fee and GPA. Both classes have some common characteristics so we extract these feature in new class called Person.
Generalization

Specialization 

If we want to add new class to a existing modal, find the similar characteristic into model but some part of behavior of new class is different are restricted for that we can use specialization. For example in previous table we had Person as parent class and teacher and student as child class now we want to add adult class with same characteristics but here age should be more then 18.
Specialization

Class Association

Class association is implemented in term of inheritance implemented generalization or specialization relationship between the classes in case of public inheritance it implement "Is A" relationship and in private inheritance "Implemented in term of" relationship. Member of base class are available to child class.

Object Association

Its interaction of one class object with a objects of other classes.

Aggregation

It is specialize form of association. In this an object may contain collection of other objects, relationship between container and contained object is known as aggregation. Here every objects have their own life cycle but they are owned by other class and these objects can't be owned by any other class. Lets take an example of  Room, here room is parent class and its child classes are chair, table, bad and mirror. If any of child class is removed it will not affect other class. It is represented by blank diamond.
Some important point of aggregation
  • Relationship between objects are "Has A"
  • Every Object have independent life
  • Child Parent relationship

Commposition

It is specialize form of Aggregation. In this an object maybe compose of other smaller objects. Its the relation of "Part and Whole". It also known as Has A  relationship and it is represented by filled diamond. In this every child class does not have life cycle they are dependant on parent class. If parent class is deleted all child class will also deleted. Lets have an example, here Human body and body parts have relationship.
Some important points of commpositon
  • Strong Relationship
  • Only Parent have independent life cycle
  • Parent child relationship

Tuesday, 21 October 2014

Free Download Project Of Linked List In C++

Linked List Basic And Simple Program 

In this program user can have six functions to select. User can Add  Node In Beginning,  In Last  can display link list, user can delete the node from specific position and also can add node for specific position in linked list and user can reverse complete linked list, finally user will have exit option to exit program.   

Header Files For Linked List Function 

#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<iomanip.h>   // For Set word

// structre for node

struct node{
    int value;
    node *next;
}*start=NULL;

int count=0;// Global Integer For Counting

// Function To Create Node In Link List (C++)

node* creatNode(int data)
{
    node *temp;
    temp= new node;  // Creating Node
    temp->value=data; //assiging value
    temp->next=NULL;
    return temp;
}

// Function To Add Node At Given Position In  Linked List C++

void addNode()
{
    int value,pos=0,key;
    node *temp=start;
    node *newNode;
    node *pre=start;
    if(start==NULL)
    {
        cout<<"Enter value:";
        cin>>value;
        temp=creatNode(value);
        start=temp;
        start->next=NULL;
        return;
    }
    cout<<"Enter Position To Add New Node:";
    cin>>key;
    if(pos==key)
    {
        cout<<"Enter value:";
        cin>>value;
        temp=creatNode(value);
        start=temp;
        start->next=pre;
        return;
    }
    else
    {
        int i=1;
        while(temp!=NULL)
        {   
            pre=temp;
            temp=temp->next;
            if(i==key)
            {
                cout<<"Enter value:";
                cin>>value;
                newNode=creatNode(value);
                newNode->next=temp;
                pre->next=newNode;
                return;
            }
            i++;
        }
    }
    cout<<"Node Position Is Not Available";   
   

}

// Function To Add Node At Beginning of Linked List C++


void insertBeg()
{
    int value;
    node *temp, *pre;
    cout<<"Enter value:";
    cin>>value;
    temp=creatNode(value);
    if(start==NULL)
    {
        start=temp;
        start->next=NULL;
    }
    else
    {
        pre=start;
        start=temp;
        start->next=pre;

    }

}

// Function To Add Node At Last of Linked List C++

void insertLast()
{
    int value;
    node *temp, *last;
    cout<<"Enter value:";
    cin>>value;
    temp=creatNode(value);//Storing addres of created Node
    if(start==NULL) // If there is no node
    {
        start=temp; 
    }
    else
    {   
        last=start;
        while(last->next!=NULL) // Checking Adress in Next
        {
            last=last->next;   //Moving Pointer to Last
        }
        temp->next=NULL; // To Make It Last
        last->next=temp;    // Connecting Last Node To New Node
    }
       

   

}



// Function To Delete Node From Linked List C++




void deleteNode(int num)
{
    int pos=1;
    node *temp, *pre;
    temp=start;            // assigning start node address to temp
    if(temp==NULL)   // Checking list is empty?
    {
        cout<<"*************List Is empty************";
        return;
    }
    if(num==pos)                    // If user want to delte first node
    {
        if(temp->next==NULL)    // checking that is first node is last?
        {
            start=NULL;        // List Will Become Empty
            cout<<"There Was Only One Node ... Now List Is Empty";
            return;
        }
        else
        {
            start=temp->next;
            return;
        }
    }
    while (temp!=NULL)
        {
            pos++;
            pre=temp;
            temp=temp->next;
           
            if(pos==num)
            {
                if(temp->next=NULL)
                {
                    pre->next=NULL;
                    cout<<"You Deleted Last Node Of Your List..."<<endl;
                    return;
                }
                else
                {
                    pre->next=temp->next;
                    return;
                }
            }
        }
}



// Displaying Linked List Function In C++

void display()
{
    node *temp;
    int num=0;
    temp=start;
    if(temp==NULL)
    {
        cout<<"Link List Is Empty...."<<endl;
        return;
    }
    cout<<"Node #"<<setw(10)<<"Value"<<endl;
    while(temp!=NULL)
    {
        cout<<setw(2)<<num<<setw(11)<<temp->value<<endl;
        temp=temp->next;
        num++;
        count++;
    }
    cout<<endl;
}


// Function Reverse Linked List C++

void reverse ()
{
    node *frw;
    node *pre=NULL;
    node *curent=start;
    while(curent!=NULL)
    {
        frw=curent->next;
        curent->next=pre;
        pre=curent;
        curent=frw;
    }
    start=pre;

}


// Main Function
int main ()
{
    int option,num;
    while(1)
    {
        system("CLS");
        cout<<endl;
        cout<<"*****Select Option********"<<endl;
        cout<<"* 1. Add In Begining     *"<<endl;
        cout<<"* 2. Add In Last         *"<<endl;
        cout<<"* 3. Display Link List   *"<<endl;
        cout<<"* 4. Delete Node         *"<<endl;
        cout<<"* 5. Reverse Node        *"<<endl;
        cout<<"* 6. Add Node At Nth Pos *"<<endl;
        cout<<"* 7. Exit                *"<<endl;
        cout<<"**************************"<<endl;
        cout<<"Enter Option From Above:";
        cin>>option;
        switch(option)
        {
        case 1:
            {
                insertBeg();
            }
            break;
        case 2:
            {
                insertLast();
            }
            break;
        case 3:
            {
                display();
                cout<<"\n Total Nodes"<<count;
                system("pause");
            }
            break;
        case 4:
            {
                display();
                if(start)
                {
                    cout<<"Enter Node Number To Delete:";
                    cin>>num;
                    deleteNode(num);
                    display();
                    system("pause");
                }
                else
                    system("pause");
            }
            break;
        case 5:
            {
                cout<<"Before Reverse"<<endl;
                display();
                reverse();
                cout<<"After Reverse"<<endl;
                display();
                system("pause");
            }
            break;
        case 6:
            {
                display();
                addNode();
            }
            break;
        case 7:
            {
                return 0;
            }
            break;
        default:
            cout<<"Invalid Option"<<endl;
        }
    }
}


If you have any issue regarding to this linked list program, please ask in the comment section.
Or if you have any question about linked list coding or other c++ programing issue post it here I will give you solution of your problem with explanation. 

Sunday, 19 October 2014

Bubble Sort With Pointer

Bubble Sort With Pointer In Data Structure

C++ Coding In Microsoft Visual 6

#include<iostream.h>
void bubleSort (int *arr);
//Main Function
void main ()
{
    int arr[5];
    cout<<"Enter Numbers To Store In Array"<<endl;
    for(int i=0; i<5; i++)
    {
        cin>>arr[i];
    }
   
   
    cout<<"Beofre Sorting"<<endl;
    for(i=0; i<5; i++)
    {
        cout<<arr[i]<<",";
    }

    //sorting array
    bubleSort(arr);
   
    cout<<"After Sorting"<<endl;
    for(i=0; i<5; i++)
    {
        cout<<arr[i]<<",";
    }

}

// Sorting Function
void bubleSort (int *arr)
{
    for(int i=0; i<4; i++)
        {
            for(int j=0; j<4; j++)
            {
                if(arr[j]>arr[j+1])
                {
                    arr[j]=arr[j]+arr[j+1];
                    arr[j+1]=arr[j]-arr[j+1];
                    arr[j]=arr[j]-arr[j+1];
                }
            }
        }
}

Saturday, 18 October 2014

Object Oriented Programming Task For Time Clock In C++

OOP Time Clock Parametrized and Default Constructor

Task To Convert Twenty Four Hour Format To Twelve Hour Format

Complete the function definitions of the following ADT
class Time
{
public:
void setTime( int, int, int ); // set hour, minute, second
void setHour( int ); // set hour
void setMinute( int ); // set minute
void setSecond( int ); // set second
int getHour(); // return hour
int getMinute(); // return minute
int getSecond(); // return second
void printTwentyFourHourFormat(); // print universal time

void printTwelveHourFormat(); // print standard time 

private:
int hour; // 0 - 23 (24-hour clock format)
int minute; // 0 - 59
int second; // 0 - 59
};


Task Solution

#include<iostream.h>
#include<iomanip.h>
class Time
    {
        public:
            void setTime( int hour, int minute, int second ) // set hour, minute, second
            {
                setHour(hour);
                setMinute(minute);
                setSecond(second);
            }
            void setHour( int h ) // set hour
            {
                hour=(h>=0 && h<24)? h:0;
            }
            void setMinute( int m ) // set minute
            {
                minute=(m>=0 && m<60)? m:0;
            }
            void setSecond( int s ) // set second
            {
                second=(s>=0 && s<60)? s:0;
            }
            int getHour() // return hour
            {
                return hour;
            }
            int getMinute() // return minute
            {
                return minute;
            }
            int getSecond() // return second
            {
                return second;
            }
            void printTwentyFourHourFormat() // print universal time
            {
                cout << setfill( '0' ) << setw( 2 ) << hour << ":" << setw( 2 ) << minute << ":" << setw( 2 ) << second;
            }
            void printTwelveHourFormat() // print standard time
            {
                cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 )
                << ":" << setfill( '0' ) << setw( 2 ) << minute
                << ":" << setw( 2 ) << second << ( hour < 12 ? " AM" : " PM" );
            }
            //Void incSec(int=1); // increment in the second (01)
            //Void incMin(int=1); // increment in the minute (01)
            //Void incHour(int=1); // increment in the hour (01)
        private:
            int hour; // 0 - 23 (24-hour clock format)
            int minute; // 0 - 59
            int second; // 0 - 59
    };

void main ()
{
    Time t;
    t.setTime(21,4,55);
    t.printTwelveHourFormat();
    cout<<endl;
    t.printTwentyFourHourFormat();
}

Saturday, 6 September 2014

Some important question before studying Software Engineering



Q1. Why we need software engineering?

Software engineering is need to make sure development of software systems (Large Software) that are
  • Reliable
  • Maintainable
  • Efficient
  • Meet the needs of customers
Production of system meets
  • Schedule
  • Budget

Q2. What is difference between Search and Research?



When someone searches, it finds something and that found something is again searched, you find something either new or missing or not there at all. So, searching something from something already searched is research in literally.

Q3. History of Software Engineering?


Mastering the Machine (1956–1967)
During this session Software Engineering was not been coined. The main reason of any part of software was to get exploitation of the limited hardware.  First compiler was defined and operating system was non interactive.  These primitive environments defined first low level CASE tools for editing, compiling, and debugging. Lack of software development and high risk was easily noticeable.
Mastering the Process (1968–1982)
First software crisis faced in this session and led to the birth of software engineering. Its aim was to improve productivity, quality and reduce risk. In this stage formal modeling introduced that enables implementation automation.  But for industry, this formal approach was unfeasible due to a lack of tools and training. Furthermore, formal methods become unmanageable for large system development. In conclusion, in this stage, the need to focus on predesign phases and the use of more or less formal models for software specification began to appear. A number of structured methods, such as Software Requirement Engineering Methodology (SREM) and the Structured Analysis and Design Technique (SADT) were developed allowing the development of specification documents for business management software.
Mastering the Complexity (1983–1992)
The up to then dominion of hardware over software ended. Personal computers arrived and opened the fields of computer applications. The software development process would now comprehensively address analysis and design from the specification. Graphical user interface and visual programming brought software closer to customers. The use of structured family and data modeling methodologies was extended . Several CASE tools facilitated software development. However, data modeling (database) and function modeling (structured methods) still followed separate paths. These two modeling paths converged in object-oriented (OO) methods like early on in structured methodologies, they were first introduced in coding and design, and finally in specification and analysis . This approach enables efficient reuse of object-oriented software and thus improves building software productivity.
Mastering the Communications (1993–2001)
The emergence of the Internet brought with it a new software concept. The decentralization of functions and data led to the rapid development and expansion of areas of computing, such as concurrent programming and distributed architectures, which up to then had been limited to a narrower context. In addition to client/server applications, and in general, any distributed system development, there was now a new engineering software discipline called Web engineering. Moreover, software development was viewed as an industrial process in which quality should be monitored. This requires an effective separation between process and product. Some tasks related to managing and improving both the product and process appeared as new SE components, such as CMM (capability maturity model) and CMMI (capability maturity model integrated) .
Mastering the Productivity (2002–2010)
Most software systems created in this stage are called management information systems. They were designed to be an important part of business management in large companies. This has led to a need for the methodologies to be adapted by increasing the abstraction levels in software engineering tasks up to the abstraction level in which the problem is described. New tools enabling analysis level programming, such as Model Driven Architecture (MDA), appeared in this stage. The other major significant period in this stage was marked by the emergence of agile methodologies. Agile projects focus on creating the best software to meet customer needs. This means that the development team focuses only on tasks and processes that provide the customer with added value in the product being created, improved, or implemented. The most popular methodologies are Extreme Programming (XP) and Scrum.
Mastering the Market (2011–…)
Now, there are new platforms for integration and interoperability between different information systems. The concept of Service Oriented Architecture (SOA) coined in the early decade is widely extended. It is based on the combination of basic services (own or outside) that provide the functionality at business level for a specific domain problem. These services are orchestrated to perform more complex tasks, becoming composite services. These ubiquitous real-time services can be sold as a product, which is the origin of Cloud computing. On the other hand, customers demand several applications to be used in their smartphones, tablets, or laptops. The applications (i.e., apps) are small programs that can be downloaded and installed on mobile devices that allow users to perform some tasks at the place that they are in any moment. They are grouped into virtual stores and many of them are free, so usually they are closer to marketing challenges than software development challenges. They tend to be more dynamic than traditional programs and are the ultimate expression of agile methods and MDA.

Q4.  Difference Between computer science and Software Engineering?

Computer Science
It is Science of Computers. Everything that is related to computers is covered in CS.CS basically involves research and development of both your hardware, software and different techniques involved with them e.g Networking, Artificial Intelligence and Cryptography. It also involves making NEW tools and technologies in the field of Computers and combination of computers with other subjects  i-e Use of computers to solve non-computer problems. Also, an important point to remember is whatever you do as a computer scientist, it becomes a part of your arsenal. You can build upon it in future. 
Software engineering SE
It deals with the application of computer science and software; to commerce or industry i-e How software effects the business objectives (Making something within reasonable time with use of reasonable labor and expenses etc). Apart from development it also deals with verification and validation e.g Software Product is according to customer requirements and according to specifications and standards.

Q5. Importance of Software Engineering in software houses?

In Software House developing large software is a complex and often difficult process requiring the synthesis of many disciplines. From modeling and design to code generation, project management, testing, deployment, change management and beyond, a UML (Unified Modeling Language) based modeling tool like Enterprise Architect has become an essential part of managing that complexity these all things are covered in software engineering.

E-mail Newsletter

Sign up now to receive breaking news and to hear what's new with us.

Recent Articles

TOP