Thursday 16 February 2012

Encapsulated SIS ?? PART I

Recently I did a project for a good friend of mine who is studying at another University. He got the problem to design a Student Information System using Object Oriented Concepts. But the Language was C++. Worst this was it was command line project means not to deal with any GUI. It was little bit hard, since I haven't done such kind of big project using command prompt, even in Java. I'm more familiar with Java.

But we did a C++ project at SLIIT as a group project. It was a system for a Phamacy. "Good Health Pharmacy". It was an quite interesting projects because it was GUI based project. I'm the one who designed all the interfaces in colorful manner.. I did less programming part there.Most of the core codes were done by my friend Tharindu Edirisinghe.


It was based on Linked lists, which was dynamic data.

So since i had this project I referred this software to do the SIS. There were no limitations and I had to consider about Object Oriented Concept and command prompt. I used linked lists as the data storing method. ..Actually it was a real challenge to me.

I used Visual studio 2008 as a IDE and use visual C++.

This is the main menu..

 I used switch caseto go through the menu items as usual.

PROBLEM?? "what if the user enters a letter rather than typing any number ? " Anyway it should be validated to manage all the inputs..Since  I have used  'int ' type variable to catch the users selection.

Yes we can filter these numbers using case statements.. BUT it gave me a exception to all invalid inputs like letters.

I googled my problem and this is what I found...

int a;
    cout<<"Your Selection : ";
    cin>>a;
    while (!cin.good())
    {
        system( "CLS" );
        cin.clear();
        cin.ignore(1024, '\n');
        cout << "Invalid Selection Type only digits..."<<endl;
        cout<<"Your Selection : ";
        cin>>a;
    }

here cin.good() true if the data type matching succeed. if not cin.clear(); will clear the last cin and cin.ignore(1024,'\n') will ignore the characters of 1024 buffer size up to a new line character. Then it re prompt to get the input.

For the most of the C++ problems I found the correct answers from
http://www.cplusplus.com/

Actually one of the good site to refer for C++ beginners.

I used a user log in part in this. so I needed a way to hide what I type in password field (in windows command prompt.)

we should include "#include <windows.h>"

    HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
    DWORD mode = 0;
    GetConsoleMode(hStdin, &mode);

    SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT));

    cin>>pass;
    cout<<endl;
    SetConsoleMode(hStdin, mode & (ENABLE_ECHO_INPUT));

Even it was bit difficult for me. I understood the part ~ENABLE_ECHO_INPUT  only it something like disabled the echo mode.
 I got this from 

http://www.cplusplus.com/forum/beginner/61174/

refer http://msdn.microsoft.com/en-us/library/windows/desktop/ms683167%28v=vs.85%29.aspx to get an idea about GetConsoleMode function.

Hope you got something out of it.... :)

****To be continued. please see  'Encapsulated SIS ?? PART II

2 comments:

  1. Great memories with Good Health Pharmacy Project.... We did it great... :D

    ReplyDelete
    Replies
    1. yaa what great project... awsm memories :D

      Delete