Wednesday, May 20, 2009

Different Programming Approaches - Library Management System

In my Institute (UIET) I learnt C, C++ and also PHP ; learnt different approaches of programming mainly procedural and object oriented. Of course I secured an A in all programming courses but several a times I was unable to decide on, which one will be better approach for a certain program. 

Whenever I was given a problem to program, My first instinct was to program that in procedural method although I could give you proper definitions and examples of all the object oriented concepts I learnt. But the problem was that I was unable to think in OOP on the first hand. 

Last few days I have been learning to mitigate this confusion.  and here, am sharing a few things with you.  
Let us consider the simplest example of Library Management System- 

SRS- Software Requirement Specification for our software-
  1. The manager should be able to add a profile (student +book).
  2. He should be able to update and remove a profile.
  3. He can issue, re-issue and return a book.
  4. He must be able to check the fine on a certain book at a certain account. 
  5. He must be able to see the list of issued or non issued books, i.e. we are looking for sorting and searching on a book or profile basis. 
Of course there can/should be a plenty of other facilities, but these which are enlisted are enough to achieve the motive of the post.

First Approach-  Procedure Oriented Programming

Divide and conquer -is called the approach, we simply think of a program  having a certain no. of small functions which do a certain job for it and then finally returning the output to its caller. Its like a hierarchy of caller and doer programs. 

Data structure - A book will have its name, a unique id no., name of publisher, course name etc. 
so the best data structure as it comes in mind is 'struct' for it is meant to collect different type of data in one single data structure. 

Similarly a student will have - A unique roll no. name, course, address etc. also the struct will do great here. 

we can define them before  'int main() ' like- 

struct book
{
int book_id;
char book_name[50];
char book_publisher[50];
char book_course[50][5];
}

struct student
{
int rollno;
char student_fname[50];
char student_lname[50];
int book_counter;
}

Now as we see there will be many profiles and ample of books, how are we gonna organize them?we can make use of array to do that, fixed or of variable size. also we can store the books and profiles in linked list- kind of data structures, oh yes, you can argue that , this can increase the overhead but think positively, it can be a great help while dynamic allocation of memory and also in arranging the books and profiles in preferred order. 
for eg- we can insert a book according to its course, id no. or may be according to the issued date or something like that. 

Then we have simple functions to get our things done, for example we will just input the name roll no and course of the student, and a function named as add_profile will add a new student profile in the linked list we just talked about. 
Similarly we can add a book, via some add_book function. 

we just need to know proper function signature to get our work done. 

But here occurs another problem- that every time you loose your library and student list as you stop execution of the program -by making use of 'file handling' we can overcome this problem. 




Friday, May 8, 2009

UIET - Last Days

I am planning this post to be a longer one- here, will share some of my cool experiences @ UIET. The first few are the dreams I saw, in last days of my college. 
 Dream-1   Let us WIN(e)D up

 Most weird and funny things we are going to do in this dream. So expect unexpected.

Its evening 5 pm.Five of us, Me, Gagandeep (GD), Akanksha (akki), Satya, and Sushil are sitting on the stairs, outside CSE building, after playing cricket match for five hours. It’s our last day at college. We are done with exams. Guys come and say bye. All are leaving to their home or hostels. And we are like- who wants to go home.

Me- Today I want to do something wild.... may be I want to drink.

GD – woo!! , yeah, I know a great place where we can do this, they provide pretty healthy wine, it’s made of all fruit juice.

 Satya- No, are u MAD. ARE THESE GIRLS GONNA DRINK?????  And u gonna let them!!!!!!!????

Akki- No, My dad will kill me if I ever do this.

Sushil-  If every one drinks , I have  no problem.

GD- Come on yaar, we all are grown up. let us go and at least give it a first try. .....................bla bla bla..He gives pretty much of good reasoning, why should we try drinking.

 Me- See, I am going, anyone!! If anyone likes to come, can come?

Akki- Ok, Shalini am coming with you. She looks at GD as if he is villain and she declares- No one is going to force us to drink!

GD- yeah, only you keep control on your self. 

Akki is frowned, twists her eyebrows and seems she wants to throw water on his face, may be some cake... or who knows if she is planning to put a lizard on his face.

Well, we all reach at the place. It does not look like a bar.

It’s just a good restaurant.

GD orders the things. I am like- remembering all bad memories related to UIET.  Also some good memories but not that much of them... Neither I want to cry, nor do I.

Satya is suggesting me to cry, and am laughing loud remembering everything.

Everyone laughs at me for am laughing so weirdly, although they are terrorized as well, for everyone is looking only at us.

We are drinking the transparent wine ......... one glass for one bad memory.

GD - 5 glasses

Satya- 4 glasses

Sushil- 2 glasses

Akki- 3 glasses

Me- 10 glasses

Oops! I am in poor situation......   10 bloody glasses of thing called wine...

Everyone is suggesting me to stop. I don’t

Satya- Stop her, she will die if she drinks one more glass..

GD--  No, let her drink as much as she can, so that she can get all her frustration out and can focus on her work.  :O  

(Bingo!! All three are into altercation, I and Sushil keep drinking. Sushil has no issues with who drinks how much! )whhhhhhhhhhaaaaaaaattttttttttttt!!!!! She already had 10 glasses, Akki is yelling on me (indirectly on GD, she thinks – its all because of him.)But GD is becoming monster of the evening.He is making me remember of- how some teacher used the word ' ye ladki (this girl) ' for me. what a torture was done by HOD while submitting our final BTP reports. How he has given me poor marks in mid sems of Algorithms. here akki drinks another glass for I got an A, gotta max marks in end sem exams. My God what we are doing....... total 56 glasses by now.

Finally Akki slapped hard on my face, and because GD asked why she slapped me.... now it’s his turn to get slapped. And guess what- Sushil is dancing, he is remembering a girl whom she met in IIT while summer internship. And here is Satya weeping like a 10 year old child for his journalist friend.Guess more- Akki drinks 10 more glasses for her first crush. 2 glasses for each crush those happened in last 4 years.  (2*10)5 glasses for the boy -her latest love cum crush. Uhh and one more for the guy who is our junior and his face matches with her crush. : P LOL

The situation now is pretty emotional.Seeing this GD calls the waiter asks for tequila.He drinks it. When we ask - why - on whose name he is doing thisHe says- can’t tell L

Then a  pin drop silence! seems everyone dived into some sweet old/new memories. I am wondering what they would have been thinking.hmm.... finally Akki says- I understand. (No more problem Akki has with GD) and Satya and Sushil are also consoling him.I am waiting, I was anticipating that he is gonna cry, but he does not. At the end- all the four are alike most "thakele types" they are speaking nothing. And this is somehow charging me. (seems I cant help myself being monster) I am no more like a drunken, rather most alive, Seems as if I really had 20 glasses of fruit juice.

Their drama does not seem to get over.Finally I call hansmukh (Ashutosh) and ask him to arrange a car, and tell him that we are not in the situation to go home by our self.As if it was an urgent protocol, he puts his skates on and appears almost immediately.Now the situation is funnier, as he sees we have been drinking....... he says he too will drink....... and he drinks (12*2) glasses. MY GOD ...yes u guessed this right he tells us - that 12 rejections he has faced by now!! LOL.(In reality I think, he never would have proposed a girl) and he ever will like to drink, but he does - 2 glasses for each rejection

Anyways…Finally we reach home.

Dream 2- Out of the tyranny 

People from Space come to my college, they choose guys and offer them a free visit to space.The criterion for selection is a “Serious face and extra ordinary physique”.Here is an offer to the selected candidates- every one of them should take one of their friends (m/f) to accompany them.* And the friend should be such that - he/she is not allowed to smile/laugh.I did not get select for I don’t fulfill the criterion.The easiest of all - they notice a dimple on my face which tells them, I do smile most of the time.At last On the day of selection they gave funny purple space suit to the selected candidates.The selected candidates are not expressing joy… If they knew doing it, why would they have got selected?We are not sad. For all happy people are on earth, but at heart everyone wants to visit space. Next day – as we enter in the class, we see- that all the selected guys are wearing there space suit, in most weird ways. A guy – Afzal, has removed his sleeves from his shirt and the sewed those purple arms with that. A girl – Liz is wearing the space suit in Marzina (of ali baba and 40 thieves) style. A boy- Vaibhav is wearing a special hat cum mask. Yellow colored, for it radiates the light and thus they will not need any electricity in space. They have got very special shoes- Green-echo friendly shoes- with a soul which leaks small amount of water. We who did not get selected, although making fun of them, but its so fascinating, we wanted to touch their special suits and hats. But anyways we hold our urge to do this. Classes are going on. All teachers congratulate them, we clap for them in every class. Its lunch time and we are out in cafeteria. A guy/friend comes to me and he asks me to accompany him.I deny by suggesting him to go with his best friend.He tells me that he is going with her GF. I wanted to say yes, but I was being snoopy, about what’s going in his mind. Anyways, finally he convinces me.I try that all my friends get adjusted with the selected guys. And here starts the funny/weird scenes. We arrange a class to train such gals and guys who are not serious faced, yet they are going space.Most serious and mugging sort of guys comes to teach us - how to make serious expressions, how to look daunting, worried and depressed.Now Vaibhav of my class is like- we never saw him smiling.He is on stage, but then while seeing me trying making a serious face he starts smiling.I smiled back, and then as I started endlessly smiling /laughing/commenting.He starts laughing.Vaibhav is laughing. We are watching him as if we are seeing earthquake.Well yes, its no less than that, he has got most wild smile, I ever came across with.He laughs like a lion. :D People outside the class peep inside to know what’s going inside. 

Teachers and students from other branches come to see us (as if we were some circus)Then comes the HOD of CSE in the scenario.He orders all teachers to schedule 5 quizzes a day for usnow :( all gets sadAll joy, laugh and chirpiness is gone. We go through the quizzes; faces are all pulled up and serious.And finally when after 2 days spaceship comes to pick us up, no one is eager or happy to visit the space.Every one is drawn.They come down the spaceship, as no one entered on time. They see all of us and gets happy - they select all of us to go to the visit.We look at each other, we don’t know whether to laugh or cry. But as together we get into spaceship. I make a comment-Finally we are out of the tyranny of HOD. Hurrey!! and we start shouting with joy. But we manage not to smile.But guess what- Vaibhav is the happiest chap, and he starts laughing. We are flying.They get puzzled whether to take us to space or not and we are like - teasing them, smiling every second moment :D