November 5, 2013
Installation of IT Guru
October 27, 2013
Abstraction
Principle of abstraction:
Abstraction Example:
Name Age Student Roll No Year of Study CGPA Employee ID Designation Salary |
Study DevelopExam GiveExam TakeExam PlaySports Eat DeliverLecture Walk |
- Name - Employee ID - Student Roll No - Designation - Year of Study - Salary - CGPA - Age |
- Study - DevelopExam - GiveExam - TakeExam - PlaySports - Eat - DeliverLecture - Walk |
Teacher’s Perspective
- Name - Employee ID - Student Roll No - Designation - Year of Study - Salary - CGPA - Age |
- Study - DevelopExam - GiveExam - TakeExam - PlaySports - Eat - DeliverLecture - Walk |
Ordinary Perspective A pet animal with Four Legs A Tail Two Ears Sharp Teeth | Surgeon’s Perspective A being with A Skeleton Heart Kidney Stomach |
Driver’s View | Engineer’s View |
Abstraction – Advantages
- It helps us understanding and solving a problem using object oriented approach as it hides extra irrelevant details of objects.
- Focusing on single perspective of an object provides us freedom to change implementation for other aspects of for an object later.
Information Hiding and Encapsulation in OOP
Real Life Examples of Information Hiding
- Your name and other personal information is stored in your brain we can’t access this information directly. For getting this information we need to ask you about it and it will be up to you how much details you would like to share with us.
- An email server may have account information of millions of people but it will share only our account information with us if we request it to send anyone else accounts information our request will be refused.
- A phone SIM card may store several phone numbers but we can’t read the numbers directly from the SIM card rather phone-set reads this information for us and if the owner of this phone has not allowed others to see the numbers saved in this phone we will not be able to see those phone numbers using phone.
Examples of Encapsulation
Ali |
Characteristics (attributes)· Name· Age |
Behavior (operations)· Walks· Eats |
Advantages of Encapsulation
- Simplicity and clarity
- Low complexity
- Better understanding
Interface and Implementation in OOP
Example – Interface of a Car
Example – Interface of a Phone
- Gear Box in car system
- Address Book in a Phone
Real Life example of separation of interface and implementations
Examples – Messages
Object-Orientation
Suppose we want to develop a fee collection system for a school for this we will need to find out related objects and their interactions as happens in real life. In this way we can say that object orientation makes it easier for us to solve our real world problems by thinking solution of the problem in terms of real world objects.
OO Models:
Objects
Ali, Car, House, Tree
Interactions
Ali lives in the house
Ali drives the car
- Something tangible (Human being, School, House, Car).
- Something conceptual (that can be apprehended intellectually for example time, date and so on…).
- State (attributes)
- Well-defined behavior (operations)
- Unique identity
State (attributes)
Color
Model
Behavior (operations)
Accelerate
Start Car
Change Gear
State (attributes)
Hours
Seconds
Minutes
Behavior (operations)
Set/Get Hours
Set/Get Seconds
Set/Get Minutes
We will assign our own generated unique ID in the model for Time object.
State (attributes)
Year
Day
Month
Behavior (operations)
Set/Get Year
Set/Get Day
Set/Get Month
- Model is the abstraction of some real word scenario. It helps us to understand that scenario.
- Object oriented model of any scenario (problem) describes that scenario (problem) in the form of interacting objects.
- We use Object Orientation because it helps us in mapping real world problem in a programming language.
- Object Orientation is achieved using objects and their relationships.
- Properties of an object are described using its data members and behavior of an object is described using its functions.
- Objects may be tangible (physical) or intangible (also called conceptual or virtual).
- Generally when we have given a certain problem description, nouns in that problem description are candidates for becoming objects of our system.
- There may be more than one aspects of an object
- It is not necessary that every object has a specific role in implementation of a problem there may be some objects without any role, like school parking in our school.
- It is easier to develop programs using Object Oriented Programming because it is closer to real life.
October 26, 2013
Windows 8.1 Password Resolved
In daily use, we do not really prefer to always type a long password that we have for our live account. Instead, what we can do is, we can very easily alter it or you can say bypass it by applying the following procedure.
Click on the search in the right panel as shown in the figure below.
After you click on search, the following panel will open. Type password. Here you see, as highlighted in the figure below. Click on “Sign-in options”.
Now, here you have different options, the most suitable and easier way is to have a four digit pin.
Click, on the change button in the “PIN” option which is the third one here.
First it will prompt you to enter your Hotmail account password which you are using to log into your windows.
Enter your password. As i did mine in the following diagram.
Now, enter your four digit pin number.
Like this.
And here you go, now when you want to log into your windows you will just have to enter the pin and it logs in.
October 10, 2013
C program to print different Star Formations using For Loop
Here is the code to print different star formations using for loop.
#include "stdio.h" int main() { int num,i,j,k,m,n,o,p; printf("Please enter a number to print the star formations \n"); scanf("%d", &num); for(i=0;i<num;i++) { for(j=0;j<num;j++) { printf("*"); } printf("\n"); } printf("\n"); j=0,i=0,k=0; // Hollow Star formation for(i=0;i<num;i++) { for(j=0;j<num;j++) { if(i==0 || i==num-1) { printf("*"); } else if(j==0 || j==num-1) { printf("*"); } else { printf(" "); } } printf("\n"); } // downward descending formation printf("\n"); j=0,i=0,k=0; for(i=num;i>0;i--) { for(j=i;j>0;j--) { printf("*"); } printf("\n"); } printf("\n"); j=0,i=0,k=0; for(i=num;i>=0;i--) { for(k=i;k<num;k++) { printf(" "); } for(j=0;j<=i-1;j++) { printf("*"); } printf("\n"); } printf("\n"); j=0,i=0,k=0; // Star formation right angle triangle. for(i=num;i>0;i--) { for(j=0;j<i-1;j++) { printf(" "); } for(k=j;k<num;k++) { printf("*"); } printf("\n"); } printf("\n"); j=0,i=0,k=0; for(i=0;i<num;i++) { for(j=0;j<=i;j++) { printf("*"); } printf("\n"); } return 0; } |
The output of the above code is following:
C program to print the hollow stars square
Here is the code.
#include “stdio.h” int main() { int num,i,j; printf("Please enter a number to print the hollow star formation \n"); scanf("%d", &num); for(i=0;i<num;i++) { for(j=0;j<num;j++) { if(i==0 || i==num-1) { printf("*"); } else if(j==0 || j==num-1) { printf("*"); } else { printf(" "); // space is printed .. } } printf("\n"); } return 0; } |
Here is the sample output.
As can be seen in the output above, for the user input, the hollow star square will be formed. The key to understand the logic of the code is as follows.
The outerloop controls the number of lines and inner loop controls the number of stars.
October 8, 2013
C program to display integers in Ascending without using Loop
#include "stdio.h" #include "conio.h" int main() { int a=0, b=0, c=0,d=0,e=0, f=0, grade; printf("Enter four numbers\n"); scanf("%d",&a); scanf("%d",&b); scanf("%d",&c); scanf("%d",&d); if(a>b && a>c && a>d) { printf("1st value that you entered is largest\n"); e=1; } else if(b>a && b>c && b>d) { printf("2nd value that you entered is largest\n"); e=2; } else if(c>a && c>b && c>d) { printf("3rd value that you entered is largest\n"); e=3; } else if(d>a && d>b && d>c) { printf("4th value that you entered is largest\n"); e=4; } // For finding smallest value if(a { printf("1st value that you entered is smallest\n"); f=1; } { printf("2nd value that you entered is smallest\n"); f=2; } { printf("3rd value that you entered is smallest\n"); f=3; } { printf("4th value that you entered is smallest\n"); f=4; } //Sorting // if(e==1 && f==2) { if(c { printf("Sorted order is \n %d %d %d %d", b,c , d, a); } else { printf("Sorted order is \n %d %d %d %d", b,d , c, a); } } else if(e==1 && f==3) { if(b { printf("Sorted order is \n %d %d %d %d", c,b , d, a); } else { printf("Sorted order is \n %d %d %d %d", c,d , b, a); } } else if(e==1 && f==4) { if(b { printf("Sorted order is \n %d %d %d %d", d,b , c, a); } else { printf("Sorted order is \n %d %d %d %d", d,c , b, a); } } // for e=2 if(e==2 && f==1) // a is smallest, b is largest { if(c { printf("Sorted order is \n %d %d %d %d",a, c , d, b); } else { printf("Sorted order is \n %d %d %d %d", a,d , c, b); } } else if(e==2 && f==3)// c is smallest { if(a { printf("Sorted order is \n %d %d %d %d", c,a , d, b); } else { printf("Sorted order is \n %d %d %d %d", c,d , a, b); } } else if(e==2 && f==4) // d is smallest { if(a { printf("Sorted order is \n %d %d %d %d", d,a , c, b); } else { printf("Sorted order is \n %d %d %d %d", d,c , a, b); } } // for c is largest i.e.. e=3 if(e==3 && f==1) // a is smallest, c is largest { if(b { printf("Sorted order is \n %d %d %d %d",a, b , d, c); } else { printf("Sorted order is \n %d %d %d %d", a,d , b, c); } } else if(e==3 && f==2)// b is smallest { if(a { printf("Sorted order is \n %d %d %d %d", b,a , d, c); } else { printf("Sorted order is \n %d %d %d %d", b,d , a, c); } } else if(e==3 && f==4) // d is smallest { if(a { printf("Sorted order is \n %d %d %d %d", d,a , b, c); } else { printf("Sorted order is \n %d %d %d %d", d,b , a, c); } } // for d is largest i.e.. e=4 if(e==4 && f==1) // a is smallest { if(b { printf("Sorted order is \n %d %d %d %d",a, b , c, d); } else { printf("Sorted order is \n %d %d %d %d", a,c , b, d); } } else if(e==4 && f==2)// b is smallest { if(a { printf("Sorted order is \n %d %d %d %d", b,a , c, d); } else { printf("Sorted order is \n %d %d %d %d", b,c , a, d); } } else if(e==4 && f==3) // d is smallest { if(a { printf("Sorted order is \n %d %d %d %d", d,a , b, d); } else { printf("Sorted order is \n %d %d %d %d", d,b , a, d); } } getch(); return 0; } |
C program to Read From a File
#include <stdio.h> #include <stdlib.h> void main() { FILE *fptr; char filename[15]; char ch; ...
-
A terminal emulation program for TCP/IP networks such as the Internet. The Telnet program runs on your computer and connects your PC to a ...
-
Voice over IP (VoIP, or voice over Internet Protocol) commonly refers to the communication protocols, technologies, methodologies, and tra...
-
Star Formations http://cs-study.blogspot.com/2013/10/c-program-to-print-different-star.html Hollow...