tag:blogger.com,1999:blog-10771326505857660352024-03-13T17:12:43.652-07:00Computer ScienceComputer Science blog is about its various fields and their corresponding developments. It's about Programming languages, Object Oriented concepts, Software Engineering, Relational Database Management Systems, Operating Systems, Internet Technologies, Computer Hardware and Software and much more.Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.comBlogger27125tag:blogger.com,1999:blog-1077132650585766035.post-43110453161450691452013-09-09T05:46:00.000-07:002013-09-09T05:46:02.956-07:00HOW JAVA IS PLATFORM INDEPENDENT<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
HOW JAVA IS PLATFORM INDEPENDENT ?</h2>
<div>
The developers of java have made compilers and java virtual machines(also known as JVM). The function of compiler is to convert the program written by the programmer in the syntax of java into byte-code. Though the programmers don't have to do anything with the byte-codes so produced by the compilers, but for the sake of general knowledge, the programmer must know that it is the compilers which are platform dependent. You must have noticed while downloading java-sdk kit from the oracle website. The website provides different kinds of compilers for different platforms such as windows, LINUX, UNIX, Machintosh. So, this means java developers bore this extra responsibility of writing different compilers for different platforms, so that you can both write and run a java program on any platform. All you need to worry about is just learning the syntax of java. </div>
<div>
<br /></div>
<h2 style="text-align: left;">
2nd PHASE AFTER BYTE-CODE FORMATION</h2>
<div>
<div>
When compilers perform their part of converting a program written in java to the byte-code, then this byte-code is fed to JVM(Java Virtual Machine) whose function is work on the byte-code and to convert it into such a form which can be understood by the computer hardware or the underlying machine. This form is referred as machine language. Java developers also take care to develop different JVM for different machines. So that your program written in java could run on any hardware. Your computer manufacturer could be any company such as Sony, Samsung, Lenovo, ASUS, etc. So there are JVMs available for all different machines.</div>
<div>
The appropriate compilers and JVMs makes life easier for the programmers who write code in java and want their code to run everywhere irrespective of different platforms.</div>
<div>
These striking features of java made the founders of java to raise the slogan :</div>
<div>
"Write once run anywhere"</div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-25874841038546208132013-09-06T22:29:00.000-07:002013-09-06T22:29:26.052-07:00ACCESS MODIFIERS IN JAVA<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
WHAT ARE ACCESS MODIFIERS IN JAVA ?</h2>
<div>
Access modifiers are the special keywords which when applied provide different types of access to the content of the class. By content I mean, the data members/ fields and methods defined in the class. There might come situations where we don't want other classes to access the fields or methods or the class and some situations where we want all the elements of the class to be accessed by any other class.</div>
<div>
Therefore, to provide different kinds of access for different kind of situations, Java has <b>Access Modifiers, </b>there are 3 kind of <b>Access Modifiers</b> :</div>
<div>
<b>1. public</b></div>
<div>
<b>2. private</b></div>
<div>
<b>3. protected</b></div>
<div>
<b><br /></b></div>
<h2 style="text-align: left;">
WHEN 'public' ACCESS MODIFIER IS USED :</h2>
<div>
<br /></div>
<div>
<b><br /></b></div>
<div>
<b><br /></b></div>
<div>
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-73378828492590381212013-09-06T06:54:00.002-07:002013-09-06T06:54:54.702-07:00DIFFERENCE BETWEEN METHOD OVERRIDING AND METHOD HIDING<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
METHOD OVERRIDING</h2>
<div>
When an instance method is written again with the same name, same number and type of parameters and same return type, in the sub-class as that of the parent-class/super-class, then this phenomenon is called as <b>method overriding.</b></div>
<div>
<b><br /></b></div>
<h2 style="text-align: left;">
<b>METHOD HIDING</b></h2>
<div>
It occurs in case of class-methods( also popularly known as static methods ). When any static-method is written again with the same name, same number and type of parameters and same return type, in the sub-class as that of the parent / super-class, then this phenomenon is called as <b>method hiding.</b></div>
<div>
<b><br /></b></div>
<div>
<b><br /></b></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-37093277356237807902013-09-05T13:14:00.000-07:002013-09-06T01:09:04.693-07:00INTRODUCTION TO INHERITANCE IN JAVA<div dir="ltr" style="text-align: left;" trbidi="on">
<h2>
INHERITANCE</h2>
<div>
The concept of inheritance much more similar as in the real world itself. Inheritance means the passing of similar traits and features from older ones to younger ones. This same concept is taken from the real life and applied in the object oriented principles of programming languages too.<br />
Necessity is the mother of invention fits better here, as in the earlier days of programming when there was no inheritance at all, programmers have to rewrite whole of the complex methods again and again which they wrote earlier in some other programme. They felt very exhausted writing these common but complex methods again and again whenever they have to write new code. They started to think of ways :<br />
1. what if they introduce some way , by which they could be able to use previously written methods from previously written codes.<br />
2. what if they find a solution to introduce a link among different piece of codes.<br />
These necessities gave birth to the concept of <b>inheritance.</b><br />
With the advent of inheritance , the above problems found solutions. Now, if some code has to re-use the previously written methods and fields in some other code, it just inherits all of them by just writing a keyword 'extends'.<br />
<br />
The programming life has become much easier with the introduction of inheritance. Java allows only single inheritance, though some other programming languages allow multiple inheritance too(e.g. C++ ).<br />
<br />
<h3 style="text-align: left;">
Single inheritance</h3>
</div>
<div>
when a class can inherit only one other class i.e. having only one parent class. This kind inheritance is called Single inheritance.</div>
<div>
<br /></div>
<h3 style="text-align: left;">
Multiple inheritance</h3>
<div>
when a class inherits more than one class i.e. having multiple parent classes. This kind of inheritance is calles Multiple inheritance.</div>
<div>
<br /></div>
<div>
e.g.</div>
<div>
<br /></div>
<div>
public class Vehicle {</div>
<div>
int numOfWheels;<br />
int topSpeed;<br />
int engineCapacity;<br />
int gears;<br />
void shiftGear(int gear) {<br />
/ / / / /<br />
/ / /<br />
}<br />
void speedUpBy(int mark){<br />
/ / / / /<br />
/ / /<br />
}<br />
}<br />
<br />
public class Motorbike <b>extends</b> Vehicle{<br />
int seats;<br />
int mileage;<br />
void start() {<br />
/ / / /<br />
/ / /<br />
}<br />
void stop() {<br />
/ / / /<br />
/ / /<br />
}<br />
}<br />
<br />
We can clearly see in above example, that Motorbike class <b>extends </b>Vehicle class in its first statement, by doing this, the Motorbike class is able to inherit all the features of Vehicle class, without having it to write all those methods again. This is how inheritance makes the coding easier than before.<br />
Here the Motorbike class is called <b>subclass. </b><br />
The Vehicle class is called <b>superclass.</b><br />
<b><br /></b>
<br />
<h3 style="text-align: left;">
<b>SUB-CLASS</b></h3>
</div>
<div>
The class that is derived from the another class is called as <b>sub-class (also called as child-class, derived class or extended class).</b></div>
<div>
<b><br /></b></div>
<h3 style="text-align: left;">
<b>SUPER-CLASS</b></h3>
<div>
The class from which sub-class is derived is called as <b>super-class ( also called as a base-class or a parent class ).</b></div>
<div>
<br />
<br />
<b>NOTE : </b>there exist</div>
<div>
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-38923552416910265432013-09-05T08:47:00.002-07:002013-09-05T09:31:34.359-07:00DIFFERENCES AND SIMILARITIES BETWEEN INTERFACES AND ABSTRACT CLASSES<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">DIFFERENCES BETWEEN INTERFACES AND ABSTRACT CLASSES</span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Here I have compiled the points of both interfaces and abstract classes, and presented them in the image form . So, that anybody can save it and make it as his/her wallpaper, which enables to see it regularly and revise it.</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-O42qcXmCJSk/UiiuoANHzgI/AAAAAAAAARE/zLLHMmCtE8E/s1600/Page_1.Jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="http://4.bp.blogspot.com/-O42qcXmCJSk/UiiuoANHzgI/AAAAAAAAARE/zLLHMmCtE8E/s640/Page_1.Jpeg" width="452" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-ssB6ibzkQNw/UiivJz06GbI/AAAAAAAAARM/kdTxmhrs3pU/s1600/Page_2.Jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="http://1.bp.blogspot.com/-ssB6ibzkQNw/UiivJz06GbI/AAAAAAAAARM/kdTxmhrs3pU/s640/Page_2.Jpeg" width="452" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-0dxVPvlqQTM/UiivmbHIcTI/AAAAAAAAARU/fKkjX-KW_io/s1600/Page_3.Jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="http://4.bp.blogspot.com/-0dxVPvlqQTM/UiivmbHIcTI/AAAAAAAAARU/fKkjX-KW_io/s640/Page_3.Jpeg" width="452" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-G8FIFUsx-VI/Uiiv2m3vniI/AAAAAAAAARc/BL-IxGlpY3U/s1600/Page_4.Jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="http://4.bp.blogspot.com/-G8FIFUsx-VI/Uiiv2m3vniI/AAAAAAAAARc/BL-IxGlpY3U/s640/Page_4.Jpeg" width="452" /></a></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-5893748935738502532013-09-04T01:46:00.000-07:002013-09-04T02:28:38.856-07:00SOLVING ANY PROBLEM FROM THE OBJECT ORIENTED POINT OF VIEW<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Objective: Analysis of the following Case Study from the perspective of Object Oriented </span><span style="font-family: Arial, Helvetica, sans-serif;">Approach</span></h2>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Problem Description: Course Registration System</span></h3>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<b><span style="font-family: Arial, Helvetica, sans-serif;"></span></b><br />
<div>
<b><span style="font-family: Arial, Helvetica, sans-serif;">A Course Registration System needs to be developed for an engineering college. The college </span><span style="font-family: Arial, Helvetica, sans-serif;">wants an automated system to replace its manual system for the purpose of registration of </span><span style="font-family: Arial, Helvetica, sans-serif;">students to branches and calculation of fees for each year. The engineering college provides </span><span style="font-family: Arial, Helvetica, sans-serif;">graduation courses in various branches of engineering.</span></b><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>
</b></span>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>The system will be used by the admin staff to register students, admitted to the college to </b><b>the branches, at the time of joining the college and also to calculate the yearly fees for the </b><b>students. The student has to register every year for the next academic year. The Admin takes </b><b>care of the yearly registration of the students and the calculation of yearly fees. The system </b><b>needs to be authenticated with a login id and password.</b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
<div>
<b>Registration of a student to a branch is based on the qualifying exam marks and the entrance </b><b>counseling. For every branch, a yearly branch fee is applicable. Discounts are given to the </b><b>branch fees of the first year based on the qualifying exam marks. In addition to this, there is <span style="font-family: Arial, Helvetica, sans-serif;">a registration fee which is applicable to the first year students. Students can opt to be a day </span><span style="font-family: Arial, Helvetica, sans-serif;">scholar or hostelite. Annual bus fee is applicable to the day scholars based on the distance </span><span style="font-family: Arial, Helvetica, sans-serif;">they travel. Annual hostel fee is applicable for all the hostelites. Annual infrastructure fees </span><span style="font-family: Arial, Helvetica, sans-serif;">and library fee is also applicable to all the students. Admin calculates the yearly college fees </span><span style="font-family: Arial, Helvetica, sans-serif;">for each student and the college fees include all the fees specified earlier based on the type </span><span style="font-family: Arial, Helvetica, sans-serif;">of student. Admin will provide a printed receipt of the fees to the students once the annual </span><span style="font-family: Arial, Helvetica, sans-serif;">college fees have been paid. </span><span style="font-family: Arial, Helvetica, sans-serif;">At the time of registration, student has to provide the permanent address and in case the </span><span style="font-family: Arial, Helvetica, sans-serif;">student is opting to be a day scholar, he/she has to provide the residential address also.</span></b><br />
<b><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b>
<b><span style="font-family: Arial, Helvetica, sans-serif;">SOLUTION :</span></b><br />
<b><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b>
<span style="font-family: Arial, Helvetica, sans-serif;">Now, after thorough reading the above problem, we need to extract some crucial points, without writing them into sentences again, because those points will take us closer to the object oriented design phase. </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Lets get started :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 1 :</b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">First of all we need to extract the purpose from the whole description given above in just few points, as it will enable us to have a clear cut target. So the purpose of above long description is as follows :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>1.</b> Registration of the students to the available branches.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b>2.</b> Calculation of annual fees.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 2 :</b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Since, we are seeing the problem from the object oriented point of view, therefore, we need to make out what kind of actors / entities / objects are involved in our problem.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">The whole problem revolves around one important object and i.e. 'Student'.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">So, <b>'Student'</b> can be seen as an <b><u>actor</u></b> or <b><u>entity</u></b> or an <u style="font-weight: bold;">object</u> .</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b><u><br /></u></b></span>
<div style="font-weight: bold;">
</div>
</div>
</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-56071419409508249122013-09-03T13:36:00.000-07:002013-09-03T22:54:27.215-07:00TOPIC 3 : INTRODUCTION TO DATA STRUCTURES<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">3.1 Data structures - Stack</span></h2>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Assignment 3.1.1: Application of Stack Data Structure</span></h3>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Objective: To understand how to apply Stack Data Structure.</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b></b></span><br />
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Problem Description: Write a pseudo code to find the binary value of a given integer and <b></b></b></span><br />
<div style="display: inline !important;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><b>display it.</b></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><b>
</b></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>
</b></span>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Hint: Consider the integer 5. To convert 5 to binary, the following procedure needs to be <b></b></b></span><br />
<div style="display: inline !important;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><b>adopted.</b></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><b>
</b></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>
<div>
<b></b><br />
<div style="display: inline !important;">
<b><br /></b></div>
<b>
</b></div>
<div>
<b></b><br />
<div style="display: inline !important;">
<b> 2|_5____</b></div>
<b>
</b></div>
<div>
<b></b><br />
<div style="display: inline !important;">
<b> 2|_2_-_1_</b></div>
<b>
</b></div>
<div>
<b></b><br />
<div style="display: inline !important;">
<b> _1__- 0_</b></div>
<b>
</b></div>
<div>
<b></b><br />
<div style="display: inline !important;">
<b><br /></b></div>
<b>
</b></div>
<div>
<b></b><br />
<div style="display: inline !important;">
<b><br /></b></div>
<b>
</b></div>
<div>
<b></b><br />
<div style="display: inline !important;">
<div>
<b>Each time, store the remainder in an appropriate data structure and use LIFO to get the <b></b></b><br />
<div style="display: inline !important;">
<b><b><b></b></b></b><br />
<div style="display: inline !important;">
<div style="display: inline !important;">
<b><b><b>binary value.</b></b></b></div>
</div>
<b><b><b>
</b></b></b></div>
<b><b>
</b></b></div>
</div>
<b>
</b></div>
</b></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-46910005972952129212013-09-03T12:25:00.003-07:002013-09-03T13:31:19.483-07:00TOPIC 2: LOGIC BUILDING USING PSEUDO CODE part-3<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">2.3 Iteration Control Structures</span></h2>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Assignment 2.3.1 Pseudo code - Iterational pattern (1)</span></h3>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Objective: Write pseudo code for iterational pattern problems.</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Problem 1 :</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b></b></span><br />
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>The problem given in Assignment 2.1.2 is extended to check whether <b></b></b></span><br />
<div style="display: inline !important;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><b>the Number of Hours accepted from the user is less than or equal to 0. If so display an error </b></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><b>
</b><b></b></b></span>
<br />
<div style="display: inline !important;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><b>message. Reenter the data the Number of Hours until valid data is entered.</b></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><b>
</b></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<br />
<div style="font-weight: bold;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b></b><br /></span>
<br />
<div style="display: inline !important;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>
</b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<div>
<div style="font-weight: bold;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b></b></span></div>
<div style="display: inline !important;">
<div style="font-weight: bold;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 1: Write the following Pseudo code</b></span></div>
<div style="font-weight: bold;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">CALC_GROSS_PAY</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">1. input No_of_Hours, Pay_Rate</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">2. while(------------) do</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">3. display "---------------------"</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">4. -------------------------------------</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">5. end while</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">6. Gross_Pay = No_of_Hours * Pay_Rate</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">7. display " The gross pay is equal to : ", Gross_Pay</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">8. end</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 2 : Fill in the missing (------) parts in the Pseudo code</b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b>We need to put a condition in the parenthesis of while ( ) loop, which could test the validity of the data input by the user for the number of hours. We need to keep the loop running displaying a message as long as the condition in the parenthesis remains true. Therefore the complete form the above pseudocode is given as :</b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b>
<b><br /></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b style="font-weight: bold;">
</b>
</span><br />
<div style="font-weight: bold;">
</div>
</div>
<span style="font-family: Arial, Helvetica, sans-serif;">
<div style="font-weight: bold;">
<div style="font-weight: normal;">
CALC_GROSS_PAY</div>
<div style="font-weight: normal;">
1. input No_of_Hours, Pay_Rate</div>
<div style="font-weight: normal;">
2. while(No_of_Hours < = 0) do</div>
<div style="font-weight: normal;">
3. display "Invalid Entry, Enter Valid Number of hours. "</div>
<div style="font-weight: normal;">
4. input No_of_Hours</div>
<div style="font-weight: normal;">
5. end while</div>
<div style="font-weight: normal;">
6. Gross_Pay = No_of_Hours * Pay_Rate</div>
<div style="font-weight: normal;">
7. display " The gross pay is equal to : ", Gross_Pay</div>
<span style="font-weight: normal;">8. end</span><b></b><br />
<div style="display: inline !important;">
<b><br /></b></div>
<b>
</b></div>
<div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
Problem 2 :</div>
<b>Write a pseudo code to calculate the Loan Balance, where a person </b><b>borrows an amount A and in return he/she agrees to make N payments per year, each of </b><b>amount P. While the person is repaying the loan, interest will accumulate at an annual </b><b>percentage rate of R, and this interest will be compounded N times a year (along with each </b><b>payment). Therefore, the person must continue paying these installments of amount P until </b><b>the original amount and any accumulated interest is repaid.</b><br />
<b><br /></b>
<b>NOTE: The formula to calculate the amount that the person needs to repay after T years is :</b><br />
<b><br /></b>
<b>Balance amount after T years = </b></div>
</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-13367323250884744792013-09-03T07:42:00.000-07:002013-09-03T11:58:50.163-07:00TOPIC 2: LOGIC BUILDING USING PSEUDO CODE<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">2.2 Selection Control Structures</span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Assignment 2.2.1: Pseudo code - Selectional pattern (1)</span></h3>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><span style="font-size: large;">Objective:</span> Write pseudo code for selectional pattern problems</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<h4 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><span style="font-size: large;">Problem Description:</span> </b>The problem given in Assignment 2.1.2 should be extended to check </span><span style="font-family: Arial, Helvetica, sans-serif;">whether the Number of Hours accepted from the user is less than or equal to 0. If so an </span><span style="font-family: Arial, Helvetica, sans-serif;">appropriate error message should be displayed.</span></h4>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>The problem given in assignment 2.1.2 is <a href="http://computer-marvels.blogspot.in/2013/09/topic-2-flowchart-and-pseudocode.html" target="_blank">here</a>.</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>The pseudo-code with required changes can be written again as :</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Calculate-Gross-Pay</span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<br />
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">1. input No_of_Hours, Pay_Rate</span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<br />
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">2. if No_of_Hours < = 0 then</span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">3. Display " The Number of hours are invalid."</span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
<div>
4. else</div>
<div>
5. Gross_Pay = No_of_Hours * Pay_Rate</div>
<div>
6. Display "Gross Pay is : ", Gross_Pay</div>
<div>
7. end</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<h3 style="text-align: left;">
Assignment 2.2.2: Selectional pattern (2)</h3>
<div>
<b><span style="font-size: large;">Objective:</span> To develop pseudo code writing skills for a given problem using certain logic.</b></div>
<div>
<b><br /></b></div>
<div>
<div style="font-weight: bold;">
<span style="font-size: large;">Case study:</span> An institution offers several programs. Each program has several courses. There <b></b><br />
<div style="display: inline !important;">
<b>are students who have opted for these courses. There are Educators who offer these courses.</b></div>
<b>
</b></div>
<div style="font-weight: bold;">
<b></b><br />
<div style="display: inline !important;">
<b><br /></b></div>
<b>
</b></div>
<div style="font-weight: bold;">
<b></b><br />
<div style="display: inline !important;">
<b>Problem 1:</b></div>
<b>
</b></div>
<div>
<div style="display: inline !important;">
<div style="font-weight: bold;">
At a given point of time we need to allocate a course to an educator for a given</div>
<div style="font-weight: bold;">
period. Before allocating a course to an educator the following conditions are to be checked.</div>
<div style="font-weight: bold;">
<div>
1. Enough number of students have registered for the course</div>
<div>
AND</div>
<div>
2. The course is added into the educator’s skill set</div>
</div>
<div style="font-weight: bold;">
<div>
AND</div>
<div>
3. Educator’s calendar is free for the given period</div>
<div>
AND</div>
<div>
4. Educator is not on leave for the given period</div>
<div>
And</div>
<div>
5. Educator has not yet completed his delivery targets Or There is no other alternative</div>
</div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
SOLUTION :</div>
<div style="font-weight: bold;">
<br /></div>
<div>
COURSE_ALLOCATION</div>
<div>
1. input course</div>
<div>
2. input num_of_students</div>
<div>
3. input educator's_skill_set, spare_time, is_on_leave, delivered_targets, allocation</div>
<div>
4. if ( (num_of_students > min_number_students) && (educator's_skill_set = course) && (spare_time = true ) && (is_on_leave = false) && (delivered_targets = true ) ) then</div>
<div>
5. set allocation = true<br />
6. end if</div>
<div>
7. display "Course is allocated. "</div>
<div>
8. end</div>
<div>
<br /></div>
<div>
<b><br /></b></div>
<div>
<b>Problem 2: For a student, following is the course qualifying criteria.</b></div>
<div>
<div style="font-weight: bold;">
1. Student has registered for the course</div>
<div style="font-weight: bold;">
2. Attended at-least 80% of the classes</div>
<div style="font-weight: bold;">
or attended at-least 60% of the classes and submitted medically unfit certificate</div>
<div style="font-weight: bold;">
3. Submitted all the assignments</div>
<div style="font-weight: bold;">
4. Completed project</div>
<div style="font-weight: bold;">
5. Scored 80% marks in the test or the retest</div>
<div style="font-weight: bold;">
<br /></div>
<div>
QUALIFYING_STUDENT</div>
</div>
<div>
1. input classes_attended, min_score</div>
<div>
2. input course_reg, medical_certificate, submitted_assignments, completed_project</div>
<div>
3. if ( ( course_reg = true ) &&(classes_attended >= 80 || (classes_attended >= 60 && medical_certificate = true ) ) && (submitted_assignments = true ) && (completed_project = true) && ( min_score >= 80)) then</div>
<div>
4. set course_qualification = true<br />
5. end if</div>
<div>
6. display "Congratulations, course has been qualified. "</div>
<div>
7. end </div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<h3 style="text-align: left;">
Assignment 2.2.3: Selectional pattern (3)</h3>
<div>
<br /></div>
<div style="text-align: left;">
<b><span style="font-size: large;">Objective:</span> To use the problem solving techniques learnt so far in a real life application.</b></div>
<div style="text-align: left;">
<b><br /></b></div>
<b>Problem 1: Take marks of a trainee in a module as input and calculate the grade and</b><br />
<b>grade points. The grade table is given below:</b><br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-ISg14CPORiE/UiX0JmbGpmI/AAAAAAAAAQA/cbayaIneArQ/s1600/Page_1.Jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="http://3.bp.blogspot.com/-ISg14CPORiE/UiX0JmbGpmI/AAAAAAAAAQA/cbayaIneArQ/s640/Page_1.Jpeg" width="451" /></a></div>
<br />
<b>SOLUTION :</b><br />
<b><br /></b>
CALC_GRADE<br />
1. input marks_obtained<br />
2. if ( marks_obtained >= 80 ) then<br />
3. grade_point = 5<br />
4. grade = A<br />
5. elseif ( marks_obtained >= 73 && marks_obtained <=79 ) then<br />
6. grade_point = 4.5<br />
7. grade = B+<br />
8. elseif ( marks_obtained >= 65 && marks_obtained <=72 ) then<br />
9. grade_point = 4<br />
10. grade = B<br />
11. elseif ( marks_obtained >= 55 && marks_obtained <=64 ) then<br />
12. grade_point = 3<br />
13. grade = C<br />
14. elseif ( marks_obtained >= 0 && marks_obtained <=54 ) then<br />
15. grade_point = 2<br />
16. grade = D<br />
17. end if<br />
18. display " The grade points obtained are equal to: ", grade_point<br />
19. display " The grade awarded is : ", grade<br />
20. end<br />
<b><br /></b>
<b><br /></b>
<b>Problem 2 :</b><br />
<b>Take marks of a trainee in all generic modules (listed below)as input and calculate the<br />Generic GPA. The method for calculating Generic GPA is as follows:</b><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-3cJyW2sWWBQ/UiYbcy4USuI/AAAAAAAAAQQ/hivGYR_ukS0/s1600/Mathematical+expression.Jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="http://3.bp.blogspot.com/-3cJyW2sWWBQ/UiYbcy4USuI/AAAAAAAAAQQ/hivGYR_ukS0/s400/Mathematical+expression.Jpeg" width="282" /></a></div>
<b><br /></b>
<b>Grade points for marks are given in previous problem and credit points are as follows:</b><br />
<b><br /></b>
<b><br /></b>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-4Kca8-cIrW4/UiYgKC3xrvI/AAAAAAAAAQc/zuuEajBlWsM/s1600/Credit+points+table.Jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="http://4.bp.blogspot.com/-4Kca8-cIrW4/UiYgKC3xrvI/AAAAAAAAAQc/zuuEajBlWsM/s400/Credit+points+table.Jpeg" width="282" /></a></div>
<b><br /></b>
<b><br /></b>
<b>SOLUTION :</b><br />
<b><br /></b>CALC_GPA<br />
1. input marks_obtained<br />
2. if ( marks_obtained >= 80 ) then<br />
3. grade_point = 5<br />
4. grade = A<br />
5. elseif ( marks_obtained >= 73 && marks_obtained <=79 ) then<br />
6. grade_point = 4.5<br />
7. grade = B+<br />
8. elseif ( marks_obtained >= 65 && marks_obtained <=72 ) then<br />
9. grade_point = 4<br />
10. grade = B<br />
11. elseif ( marks_obtained >= 55 && marks_obtained <=64 ) then<br />
12. grade_point = 3<br />
13. grade = C<br />
14. elseif ( marks_obtained >= 0 && marks_obtained <=54 ) then<br />
15. grade_point = 2<br />
16. grade = D<br />
17. end if<br />
18 GPA = ( marks_obtained * grade_point ) / marks_obtained<br />
19. display " The grade points are : ", grade_point<br />
20. display " The GPA obtained : ", GPA<br />
21. end</div>
</div>
</div>
</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-33418292311230916102013-09-03T00:56:00.000-07:002013-09-03T01:10:56.429-07:00PSEUDO-CODES IN PROGRAMMING<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">WHAT ARE PSEUDO-CODES ?</span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>The pseudo- code is step by step representation written in plain english of an algorithm, which can be perceived as the initial stage of formal coding. Instead of directly digging upon the proper code, it is preferred to write pseudocode to get an essence of the logic applied in the algorithm.</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Some of the conventions, keywords etc. followed while writing a pseudo-code are as follows :</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>1. 'input' keyword is used to take the input from the user.</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>2. 'display' keyword is used to show the result.</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>3. Mathematical expressions are used as we do normally.</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>4. For decision making constructs, 'if' , 'then', 'else' , 'else if' keywords are used.</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>5. When some statements are to be repeated for a known number of times, 'for', 'to', 'do', 'end for' keywords are used.</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>6. When some statements are to be repeated as long as some condition remains true then , 'while', 'end while' keywords are used.</b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<br />
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">TYPES OF PSEUDO-CODES</span></h2>
</div>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;">1. SEQUENTIAL PATTERN ( the statements are executed in the same order as it is written)</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;">2. SELECTIONAL PATTERN ( they involve decision making situations )</span></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;">3. ITERATIONAL PATTERN ( they involve repitition of the statements )</span></span></h3>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;"><br /></span></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-1706983337827633892013-09-02T23:45:00.000-07:002013-09-03T03:06:17.147-07:00TOPIC 2: LOGIC BUILDING USING PSEUDO CODE<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">2.1 Flowchart and Pseudo Code</span></h2>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Assignment 2.1.2: Pseudo code- Sequential pattern</span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></h3>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Objective: Writing pseudo code for sequence pattern problems</span></h3>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>Problem Description: </b></span><b><span style="font-family: Arial, Helvetica, sans-serif;">The finance department of a company wants to calculate the gross pay </span></b><b><span style="font-family: Arial, Helvetica, sans-serif;">of an employee in the company. The number of hours worked by the employee and the pay </span></b><b><span style="font-family: Arial, Helvetica, sans-serif;">rate should be accepted from the user and the gross pay should be calculated as the below </span></b><b><span style="font-family: Arial, Helvetica, sans-serif;">formula.</span></b></div>
<div>
<br /></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Calculate-Gross-Pay</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>1. input No_of_Hours, Pay_Rate</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>2. Gross_Pay = No_of_Hours * Pay_Rate</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>3. Display "Gross Pay is : ", Gross_Pay</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif;">The above given set of statements represents a pseudo code, which can be perceived as the initial stage of formal coding. It represents a step by step approach to solve any problem in plain english, instead of formal syntax used in any particular programming language. </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">There are few conventions which are followed while writing a pseudo code as :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">1. use of keyword 'input', whenever data is retrieved from the user</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">2. use of keyword 'display', whenever result is to be displayed</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">3. Mathematical expressions are used as it is, as we normally use them.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">4. if, then, else, end if keywords are used for decision making situations</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">5. for, to , do , end for keywords are used when certain steps are to repeated for a known number of times.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">6.while, end while keywords are used when some of the steps are to repeated as long as certain condition remains true.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Assignment 2.1.3: Understanding Variables & Constants</span></h3>
</div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Problem 1 :</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b></b></span><br />
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Write a pseudo code to take the height of the building in variable <b></b></b></span><br />
<div style="display: inline !important;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><b>“Building_Height” and display the same.</b></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><b>
</b></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<br />
<div style="font-weight: bold;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b></b><br /></span>
<br />
<div style="display: inline !important;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>
</b></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<br />
<div style="font-weight: bold;">
<span style="font-family: Arial, Helvetica, sans-serif;">SOLUTION :</span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<div style="font-weight: bold;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
<div>
DISP_HEIGHT</div>
<div>
1. input Building_Height</div>
<div>
2.display "The height of the building is : ", Buildiing_height</div>
<div>
3. end</div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
<b>Problem 2 :</b></div>
<div>
<div style="font-weight: bold;">
<b></b></div>
<div style="font-weight: bold;">
<b>Write a pseudo code to take the constant value 3.142 in a variable “pi” and</b></div>
<div style="font-weight: bold;">
display the same.</div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
SOLUTION :</div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
<span style="font-weight: normal;">DISP_PI</span></div>
<div>
1. input<b> </b>pi = 3.142<br />
2. display "The value assigned to pi is : " pi<br />
3. end<br />
<br />
<br />
<h3 style="text-align: left;">
Assignment 2.1.4: Understanding Operators</h3>
</div>
<div>
<b><br /></b>
<b>Problem 1 : </b></div>
<div>
<div style="font-weight: bold;">
Write a pseudo code to take two numbers as input in variables a and b and display</div>
<div style="font-weight: bold;">
i. Product of the two numbers a and b</div>
<div style="font-weight: bold;">
ii. Sum of the two numbers a and b</div>
<div style="font-weight: bold;">
iii. Values of a-b and b-a</div>
<div style="font-weight: bold;">
iv. Quotient and remainder for a/b and b/a</div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
SOLUTION :</div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
i ) </div>
<div>
PROD_OF_TWO_NUM</div>
<div>
1. input a, b</div>
<div>
2. Product = a * b</div>
<div>
3. Display " The product of 'a' and 'b' is: ", Product</div>
<div>
4. end</div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
ii)</div>
<div>
SUM_OF_TWO_NUM</div>
<div>
1. input a, b</div>
<div>
2. Sum = a + b</div>
<div>
3. Display " The sum of 'a' and 'b' is : ", Sum</div>
<div>
4. end</div>
<div style="font-weight: bold;">
<br /></div>
<div style="font-weight: bold;">
iii)</div>
<div>
DIFFERENCE_BETWEEN</div>
<div>
1. input a, b</div>
<div>
2. Diff_A_and_B = a - b</div>
<div>
3. Diff_B_and_A = b-a</div>
<div>
4. Display "the difference of 'a' and 'b' is : ", Diff_A_and_B</div>
<div>
5. Display "the difference of 'a' and 'b' is : ", Diff_B_and_A</div>
<div>
6. end</div>
<div style="font-weight: bold;">
<b><br /></b></div>
<div style="font-weight: bold;">
<b>iv) </b></div>
<div>
QUOTIENT_REM</div>
<div>
1. input a, b</div>
<div>
2. Quo_A_by_B = a / b</div>
<div>
3. Rem_A_by_B = a % b</div>
<div>
4. Quo_B_by_A = b / a</div>
<div>
5. Rem_B_by_A = b % a</div>
<div>
6. Display "the quotient of 'a' by 'b' is : ", Quo_A_by_B</div>
<div>
7. Display "the quotient of 'b' by 'a' is : ", Quo_B_by_A</div>
<div>
8. Display "the remainder from 'a' by 'b' is : ", Rem_A_by_B</div>
<div>
9. Display "the remainder from 'b' by 'a' is : ", Rem_B_by_A</div>
<div>
10. end</div>
<div style="font-weight: bold;">
<b><br /></b></div>
<div style="font-weight: bold;">
<b><br /></b></div>
<div style="font-weight: bold;">
<b>Problem 2:</b></div>
<div style="font-weight: bold;">
<b></b><br />
<div>
<b>Write a pseudo code to take the height and width of a rectangle in variables</b></div>
<b>
</b>
<br />
<div>
<b>height and width respectively and display the rectangle's area and perimeter.</b></div>
<b>
</b>
<div>
<b><br /></b></div>
<b>
<div>
SOLUTION :</div>
<div>
<br /></div>
</b></div>
<div>
RECTANGLE_AREA_PERIMETER<br />
1. input height, width<br />
2. Area = height * width<br />
3. Perimeter = 2*(height +width)<br />
4. Display "The area of rectangle is : ", Area<br />
5. Display "The perimeter of rectangle is : ", Perimeter<br />
6. end<br />
<br />
<br />
<b>Problem 3:</b><br />
<b>Write a pseudo code to take the radius of a circle in variable radius and display</b><br />
<b></b><br />
<b>its area and perimeter.</b><br />
<b><br /></b>
<b>SOLUTION :</b><br />
<b><br /></b>
CIRCLE_AREA_PERIMETER<br />
1. input radius<br />
2. Area = 22/7(radius * radius)<br />
3. Perimeter = 2 *( 22/7) * radius<br />
4. Display "The area of circle is : ", Area<br />
5. Display "The perimeter of circle is : ", Perimeter<br />
6. end<br />
<br />
<br />
<b>Problem 4:</b><br />
<b>Write a pseudo code to take the starting value, common difference and the</b><br />
<b>number of terms of an arithmetic progression in variables a, d and n respectively and display </b><b>its nth term and sum of n terms.</b><br />
<b><br /></b>
<b>SOLUTION :</b><br />
<b><br /></b>
ARITHMETIC_PROGRESSION<br />
1. input a, d, n<br />
2. Nth_term = a+((n-1)*d)<br />
3. Sum_of_terms = (n/2)*((2*a)+((n-1)*d))<br />
4. Display " The nth term is : ", Nth_term<br />
5. Display "The sum of terms is : ", Sum_of_terms<br />
6. end<br />
<br />
<br />
<b>Problem 5:</b><br />
<b>Write a pseudo code to take the radius of the sphere in variable radius and</b><br />
<b></b><br />
<b>display the volume of the sphere.</b><br />
<b><br /></b>
<b>SOLUTION :</b><br />
<b><br /></b>
VOLUME_OF_SPHERE<br />
1. input radius<br />
2. Volume = (4/3)*3.14*(radius*radius*radius)<br />
3. Display " The volume of the sphere is : ", Volume<br />
4. end<br />
<br />
<br />
<br />
<br /></div>
</div>
<div style="font-weight: bold;">
</div>
</div>
</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-61346120854541403232013-09-02T10:13:00.000-07:002013-09-02T13:33:24.008-07:00FLOWCHARTS IN PROGRAMMING<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">WHAT ARE FLOWCHARTS ?</span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Flowcharts are graphical means of representing the logic to solve any computational problem.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">It is a pictorial way and hence give more intense understanding of the solution for the problem at hand.It consist of some symbols which forms its tools to make a complete structure for any problem.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">These symbols are : </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"> <table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-lZQqIzmQN2A/UiT0uYPFd_I/AAAAAAAAAPk/OqxaYkoXTnQ/s1600/flowchart+symbols.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" height="442" src="http://4.bp.blogspot.com/-lZQqIzmQN2A/UiT0uYPFd_I/AAAAAAAAAPk/OqxaYkoXTnQ/s640/flowchart+symbols.png" title="Flowchart Symbols" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Flowchart Symbols</td></tr>
</tbody></table>
<br />
</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">An example to show a perfect flowchart :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-9dYswcP5K1E/UiT1e77RXoI/AAAAAAAAAPw/8cR2qlt1e4E/s1600/Check+whether+number+is+prime+or+not-page-001.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" height="640" src="http://4.bp.blogspot.com/-9dYswcP5K1E/UiT1e77RXoI/AAAAAAAAAPw/8cR2qlt1e4E/s640/Check+whether+number+is+prime+or+not-page-001.jpg" title="Flowchart to show whether a number is prime or not" width="452" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Flowchart to check whether a number is prime or not</span></td></tr>
</tbody></table>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-7078841560664693292013-08-28T23:09:00.000-07:002013-09-03T03:04:43.627-07:00TOPIC 2: LOGIC BUILDING USING PSEUDO CODE<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">2.1 Flowchart and Pseudo Code</span></h2>
<h3 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Assignment 2.1.1: Problem Solving through flowchart</span></h3>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Problem Description: Draw a flowchart for the following problems:</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><span style="font-size: large;">1.</span></b> <span style="font-size: large;">Add first N even numbers</span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>SOLUTION : </b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-2oVz-5taaPA/UiTpZ6WkiTI/AAAAAAAAAOc/FMunfzqbTFg/s1600/Addition+of+even+numbers-page-001.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" height="640" src="http://1.bp.blogspot.com/-2oVz-5taaPA/UiTpZ6WkiTI/AAAAAAAAAOc/FMunfzqbTFg/s640/Addition+of+even+numbers-page-001.jpg" title="adding first 'n' even numbers " width="451" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">flowchart to show addition of first 'n' even numbers</span></td></tr>
</tbody></table>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><span style="font-size: large;">2.</span> </b><span style="font-size: large;">Add first n odd numbers</span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>SOLUTION :</b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-MqPlYKEKuEc/UiTqo9ky2GI/AAAAAAAAAOo/cGwCSUVWoWI/s1600/Addition+of+n+odd+numbers-page-001.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" height="640" src="http://1.bp.blogspot.com/-MqPlYKEKuEc/UiTqo9ky2GI/AAAAAAAAAOo/cGwCSUVWoWI/s640/Addition+of+n+odd+numbers-page-001.jpg" title="flowchart showing addtion of first 'n' odd numbers" width="452" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Flowchart showing addition of first 'n' odd numbers</span></td></tr>
</tbody></table>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><span style="font-size: large;">3</span>. </b><span style="font-size: large;">Find maximum of three numbers</span></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large;"><br /></span></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>SOLUTION :</b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-Aml_lZI3Cw8/UiTr1nlvzdI/AAAAAAAAAOw/wdq5qCiwMiY/s1600/FIND+MAX+OF+THREE+NUMBERS-page-001.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" height="640" src="http://4.bp.blogspot.com/-Aml_lZI3Cw8/UiTr1nlvzdI/AAAAAAAAAOw/wdq5qCiwMiY/s640/FIND+MAX+OF+THREE+NUMBERS-page-001.jpg" title="flowchart showing maximum of three numbers" width="452" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Flowchart showing maximum of three numbers</span></td></tr>
</tbody></table>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large;"><br /></span></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large;"><b>4. Determine whether a year s leap year or not</b></span></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large;"><b><br /></b></span></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>SOLUTION :</b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-sWeCHGQX3bU/UiTskOXVkHI/AAAAAAAAAO4/lK09YvTgReY/s1600/FINDING+LEAP+YEAR-page-001.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" height="640" src="http://3.bp.blogspot.com/-sWeCHGQX3bU/UiTskOXVkHI/AAAAAAAAAO4/lK09YvTgReY/s640/FINDING+LEAP+YEAR-page-001.jpg" title="flowchart showing whether a year is leap year or not" width="452" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Flowchart showing whether a year is leap year or not</span></td></tr>
</tbody></table>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>5. Input a number and check whether it is prime or not</b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>SOLUTION :</b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-qeUQIb0Q_Is/UiTtMd7b38I/AAAAAAAAAPE/Jb12AtHHNJ8/s1600/Check+whether+number+is+prime+or+not-page-001.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" height="640" src="http://3.bp.blogspot.com/-qeUQIb0Q_Is/UiTtMd7b38I/AAAAAAAAAPE/Jb12AtHHNJ8/s640/Check+whether+number+is+prime+or+not-page-001.jpg" title="flowchart showing whether a number is prime or not" width="452" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Flowchart showing whether a number is prime or not</span></td></tr>
</tbody></table>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>6. Input a number and check whether it can be expressed as some positive integer power </b></span><b style="font-family: Arial, Helvetica, sans-serif; font-size: x-large;">of 2. For example 2,4,8,16,32… etc. can expressed as some positive integer power of 2 </b><b style="font-family: Arial, Helvetica, sans-serif; font-size: x-large;">like 2^1</b><b style="font-family: Arial, Helvetica, sans-serif; font-size: x-large;">,2^2,2^3,2^4, and 2^5……..</b><br />
<b style="font-family: Arial, Helvetica, sans-serif; font-size: x-large;"><br /></b>
<b style="font-family: Arial, Helvetica, sans-serif;">SOLUTION : </b><br />
<b style="font-family: Arial, Helvetica, sans-serif;"><br /></b>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-O66HjNZXGWQ/UiTt1qCf95I/AAAAAAAAAPM/y-SnVik3EGE/s1600/Expressing+the+number+as+power+of+2-page-001.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" height="640" src="http://1.bp.blogspot.com/-O66HjNZXGWQ/UiTt1qCf95I/AAAAAAAAAPM/y-SnVik3EGE/s640/Expressing+the+number+as+power+of+2-page-001.jpg" title="Flowchart expressing a number as power of 2" width="452" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Flowchart expressing a number as power of 2</span></td></tr>
</tbody></table>
<b style="font-family: Arial, Helvetica, sans-serif;"><br /></b></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-43392796195072941772013-08-26T09:08:00.000-07:002013-09-02T11:48:54.444-07:00INFOSYS FOUNDATION TRAINING PROGRAM (FTP) SOLUTION FOR LAB-GUIDE ASSIGNMENT PROBLEM SOLVING AND LOGIC BUILDING- part-2<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">TOPIC 1 : COMPUTATIONAL PROBLEM SOLVING</span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>1.1 COMPUTATIONAL PROBLEM SOLVING AND ALGORITHM</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div>
<span style="color: #333333; font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 14px; line-height: 19px;"><b>ASSIGNMENT 1.1.1 : PROBLEM SOLVING EXERCISES ( part-b )</b></span></span></div>
<div>
<span style="color: #333333; font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 14px; line-height: 19px;"><b><br /></b></span></span></div>
<div>
<span style="color: #333333; font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 14px; line-height: 19px;"></span></span><br />
<div>
<span style="color: #333333; font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 14px; line-height: 19px;"><b>1.</b> In an objective type programming contest, following are the rules</span></span></div>
<span style="color: #333333; font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 14px; line-height: 19px;">
</span></span>
<br />
<div>
<span style="color: #333333; font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 14px; line-height: 19px;">a. It will have multiple rounds.</span></span></div>
<span style="color: #333333; font-family: Arial, Helvetica, sans-serif;">
</span>
<br />
<div style="font-size: 14px; line-height: 19px;">
<span style="color: #333333; font-family: Arial, Helvetica, sans-serif;">b. In each round, every participant will get a set of 10 question out of which</span></div>
<span style="color: #333333; font-family: Arial, Helvetica, sans-serif;">
</span>
<div style="font-size: 14px; line-height: 19px;">
<span style="color: #333333; font-family: Arial, Helvetica, sans-serif;">one question is marked as star question (The toughest one).</span></div>
<span style="color: #333333; font-family: Arial, Helvetica, sans-serif;">
<div style="font-size: 14px; line-height: 19px;">
c. The participant will get the next set, only if 50% of the questions are</div>
<div style="font-size: 14px; line-height: 19px;">
marked correctly in the previous round or he attempted the star question</div>
<div style="font-size: 14px; line-height: 19px;">
correctly. Otherwise he will be out of the contest.</div>
<div style="font-size: 14px; line-height: 19px;">
It is found that in each round 50% of the participants are not able to attempt 50%</div>
<div style="font-size: 14px; line-height: 19px;">
of the questions correctly but one out of those 50% participants, attempts the</div>
<div style="font-size: 14px; line-height: 19px;">
star question correctly.</div>
<div style="font-size: 14px; line-height: 19px;">
If only 4 participants are left for the 5th round what was the number of</div>
<div>
<div style="font-size: 14px; line-height: 19px;">
participants in the first round?</div>
<div style="font-size: 14px; line-height: 19px;">
<br /></div>
<div style="font-size: 14px; line-height: 19px;">
<b><u>SOLUTION :</u></b></div>
<div style="font-size: 14px; line-height: 19px;">
<b><u><br /></u></b>
Let the students appeared for 1st round be = x</div>
<div style="font-size: 14px; line-height: 19px;">
<b><br /></b>
<b>Students appearing for the 2nd round :</b></div>
<div style="font-size: 14px; line-height: 19px;">
Since half of them made for the 2nd round, which constitute = x / 2</div>
<div style="font-size: 14px; line-height: 19px;">
and 1 candidate who attempted star question</div>
<div style="font-size: 14px; line-height: 19px;">
So, total students who made for the 2nd round are = x/ 2 + 1 = (x + 2)/ 2</div>
<div style="font-size: 14px; line-height: 19px;">
<br /></div>
<div style="font-size: 14px; line-height: 19px;">
<b>Students appearing for the 3rd round :</b></div>
<div style="font-size: 14px; line-height: 19px;">
Since half of the previous round students made for the 3rd round, which constitute = ( (x + 2)/ 2 )/2</div>
<div style="font-size: 14px; line-height: 19px;">
and 1 candidate who attempted star question</div>
<div style="font-size: 14px; line-height: 19px;">
So, total students who made for the 2nd round are = ( (x + 2)/ 4 ) + 1 = (x + 6)/ 4</div>
<div style="font-size: 14px; line-height: 19px;">
<br /></div>
<div style="font-size: 14px; line-height: 19px;">
<b>Students appearing for 4th round :</b></div>
<div style="font-size: 14px; line-height: 19px;">
Since half of the previous round students made for the 3rd round, which constitute = ( (x + 6)/ 4 )/2</div>
<div style="font-size: 14px; line-height: 19px;">
and 1 candidate who attempted star question</div>
<div style="font-size: 14px; line-height: 19px;">
So, total students who made for the 2nd round are = ( (x + 6)/ 8 ) + 1 = (x + 14)/ 8</div>
<div style="font-size: 14px; line-height: 19px;">
<br /></div>
<div style="font-size: 14px; line-height: 19px;">
<b>Students appearing for 5th round :</b></div>
<div style="font-size: 14px; line-height: 19px;">
Since half of the previous round students made for the 3rd round, which constitute = ( (x + 14)/ 8 )/2</div>
<div style="font-size: 14px; line-height: 19px;">
and 1 candidate who attempted star question</div>
<div style="font-size: 14px; line-height: 19px;">
So, total students who made for the 2nd round are = ( (x + 14)/ 16 ) + 1 = (x + 30)/ 16</div>
<div style="font-size: 14px; line-height: 19px;">
<br /></div>
<div style="font-size: 14px; line-height: 19px;">
<br /></div>
<div style="font-size: 14px; line-height: 19px;">
Since it is given that the number of students appeared for the 5th round are = 4</div>
<div style="font-size: 14px; line-height: 19px;">
<br /></div>
<div style="font-size: 14px; line-height: 19px;">
This implies the expression we got for the 5th round i.e. (x + 30)/ 16 becomes = 4</div>
<div style="font-size: 14px; line-height: 19px;">
i.e. (x + 30)/ 16 = 4</div>
<div style="font-size: 14px; line-height: 19px;">
(x + 30 ) = 64</div>
<div style="font-size: 14px; line-height: 19px;">
x = 64 - 30</div>
<div style="font-size: 14px; line-height: 19px;">
x = 34</div>
<div style="font-size: 14px; line-height: 19px;">
<br /></div>
<div style="font-size: 14px; line-height: 19px;">
Since we assumed ' x ' to be the number of students present during the 1st round, which came out to be = 34. It means there were total of 34 students present in the 1st round.</div>
<div style="font-size: 14px; line-height: 19px;">
<br /></div>
<div style="font-size: 14px; line-height: 19px;">
<br /></div>
<span style="font-size: 14px; line-height: 19px;"><b>2.</b> A farmer had a lazy son. The farmer wanted his son to work in the farm. So he </span><span style="font-size: 14px; line-height: 19px;">offered that the son will work for 50 days, for each day the son works, he will </span><span style="font-size: 14px; line-height: 19px;">get 10 rupees, for each day he will not work, he need to pay back 15 rupees to </span><span style="font-size: 14px; line-height: 19px;">his father. At the end of 50 days, when the son counted his income, it turned out </span><span style="font-size: 14px; line-height: 19px;">that he had not got anything. How many days did the son actually worked?</span><br />
<span style="font-size: 14px; line-height: 19px;"><br /></span>
<span style="font-size: 14px; line-height: 19px;"><b><u>SOLUTION :</u></b></span><br />
<span style="font-size: 14px; line-height: 19px;"><b><u><br /></u></b></span>
<span style="font-size: 14px; line-height: 19px;">Let the son worked for = x days</span><br />
<span style="font-size: 14px; line-height: 19px;">money earned for x days = 10x</span><br />
<span style="font-size: 14px; line-height: 19px;"><br /></span>
<span style="font-size: 14px; line-height: 19px;">No. of days on which he didn't work = (50 - x)</span><br />
<span style="font-size: 14px; line-height: 19px;">Money he lost for days he didn't work = 15 ( 50 - x )</span><br />
<span style="font-size: 14px; line-height: 19px;"><br /></span>
<span style="font-size: 14px; line-height: 19px;">It is given in that the money he earned balances the money he paid back, which means :</span><br />
<span style="font-size: 14px; line-height: 19px;"><br /></span>
<span style="font-size: 14px; line-height: 19px;"> 10x = </span><span style="font-size: 14px; line-height: 19px;">15 ( 50 - x )</span><br />
<span style="font-size: 14px; line-height: 19px;"> 10x = 750 - 15x</span><br />
<span style="font-size: 14px; line-height: 19px;"> 25x = 750</span><br />
<span style="font-size: 14px; line-height: 19px;"> x = 750/25</span><br />
<span style="font-size: 14px; line-height: 19px;"> x = 30</span><br />
<span style="font-size: 14px; line-height: 19px;">Since we assumed ' x ' to be the number of days for which son worked, which came out to be = 30 days. Therefore, Son worked for 30 days.</span></div>
</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-62645066368643460632013-08-26T06:29:00.001-07:002013-09-02T11:48:01.550-07:00INFOSYS FOUNDATION TRAINING PROGRAM (FTP) SOLUTION FOR LAB-GUIDE ASSIGNMENT PROBLEM SOLVING AND LOGIC BUILDING<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">TOPIC 1 : COMPUTATIONAL PROBLEM SOLVING</span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>1.1 COMPUTATIONAL PROBLEM SOLVING AND ALGORITHM</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>ASSIGNMENT 1.1.1 : PROBLEM SOLVING EXERCISES</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">1 . The King ordered his servants to fill up his treasury. Each of the 3 servants, had to go to the treasury, count how much gold coins there was at that moment, and then triple it and leave. But then the King felt sorry for them and thought that he should probably reward the servants in some way, so he let each of them take 1 gold coin out before leaving. Once again the King had a good luck. He collected exactly 500 gold coins in the treasury. How much gold coins did he have before the order.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>SOLUTION</b></span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">Let initially coins be = x</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">a servant has to make thrice of them, which means, coins should be = 3x</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">and a servant is allowed to take 1 coin, which leave the total coins to = ( 3x - 1 )</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Next servant comes and does the same thing of making the count of coins to 3-times, which makes the present count to = 3 ( 3x - 1 )</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">and when he take 1-coin out , then the present count becomes = </span>( 3 ( 3x - 1 ) - 1 )<br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Finally the 3rd servant comes and make the present count to thrice again making it = </span><br />
3 ( 3 ( 3x - 1 ) - 1 )<br />
<span style="font-family: Arial, Helvetica, sans-serif;">and when he also takes 1-coin out, the total count becomes = ( </span>3 ( 3 ( 3x - 1 ) - 1 ) <span style="font-family: Arial, Helvetica, sans-serif;">-1 )</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">At last, it was found that the total count of the coins = 500</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">which means our expression </span><span style="font-family: Arial, Helvetica, sans-serif;">( </span>3 ( 3 ( 3x - 1 ) - 1 ) <span style="font-family: Arial, Helvetica, sans-serif;">-1 ) = 500</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">solving this expression step by step :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> ( 3 ( 9x - 3 - 1) - 1 ) = 500</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> 27x - 12 - 1 = 500</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> 27x -13 = 500</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> 27x = 513</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> x = 513 / 27</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> x = 19</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">since ' x ' is the number of coins initially present in the treasury. It means 19 coins were initially present in the treasury.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">2. John decided to start working. He was hired on the following terms: during 30 days, for each day John works, he gets 6 dollars, for each day he doesn't work,he pays back 9 dollars. At the end of the month, when they counted his wages, it turned out that he had not got anything. How many days did John actually work?</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>SOLUTION :</b></span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">Let the number of days for which Jhon worked be = x</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">This implies, the number days for which Jhon didn't work = 30 - x</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Jhon gets 6 $ for each day he works</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">therefore, his total wages for his working days become = 6x</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Jhon has to pay back 9 $ for the day he don't work</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">therefore, he has to pay back total of = 9( 30 - x )</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Since Jhon gets nothing at the end of the month as the money he has to pay back balances the money he earned, which means : </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"> 6x = 9( 30 - x )</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> 6x = 270 - 9x</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> 15x = 270</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> x = 270 / 15</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> x = 18</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Since, we assumed ' x ' to be the number of days for which Jhon worked, and it comes out to be 18 days for which Jhon worked for the company.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">3. Smith's boss proposed to pay him in the following way: </span><span style="font-family: Arial, Helvetica, sans-serif;">"See, there is some money in the purse. Every day I'll add 5 dollars to it, and then </span><span style="font-family: Arial, Helvetica, sans-serif;">you'll take out half of what's in it”. Three days later it turned out that there were</span><span style="font-family: Arial, Helvetica, sans-serif;">6 dollars left in the purse. How much did Smith get for three days' work ?</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>SOLUTION :</b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Let the amount of money present in the purse initially be = x</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">1st day The boss added 5 $ to the purse and the total amount becomes = x + 5</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">The employee took half of the total amount , which means, he took = ( x+ 5 ) / 2.............(i)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Money left behind in the purse = (x + 5 ) - ( x + 5 ) /2</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">2nd day The boss added 5 $ again to the purse, which makes the total amount present in the purse to = 5 + ( x + 5 )/ 2 = (10 + x + 5) / 2 = ( x + 15 )/ 2</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">The employee took half of the amount present in the purse , which means, for this time, he took-</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">( x + 15 )/ 2*2 = ( x + 15 )/ 4................................(ii)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Money left behind in the purse = ( x + 15 )/ 2 - ( x + 15 )/ 4 = ( x + 15 )/ 4</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">3rd day The boss added 5 $ again to the purse, which makes the total amount present in the purse to = 5 + ( x + 15 )/ 4 = ( x + 35 ) / 4</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">The employee took half of the amount present in the purse , which means, for this time, he took-</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">( x + 35 ) / 4 *2 = ( x + 35 ) / 8..............................(iii)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Money left behind in the purse = ( x + 35 ) / 4 - ( x + 35 ) / 8 = ( x + 35 ) / 8</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Since money left in the purse on 3rd day = ( x + 35 ) / 8</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">and it is given that on 3rd day money present in the purse = 6 $</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">which means :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> ( x + 35 ) / 8 = 6</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> x + 35 = 48</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> x = 13</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Since, we assumed ' x ' as the money present in the purse initially, which means there were 13 $ present in the purse initially.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">We've to find out the amount earned by the employee on 3rd day, which we can calculate by adding (i), (ii) and (iii) expressions above as :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"> ( ( x+ 5 ) / 2 ) + ( ( x + 15 )/ 4 ) + ( ( x + 35 ) / 8 )</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Putting 13 in place of x, we get the expression as :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> ( ( 13 + 5 ) / 2 ) + ( ( 13 + 15 ) / 4) + ( ( 13 + 35 ) / 8) </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> ( 18/ 2 ) + (28 / 4 ) + (48 / 8 )</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> 9 + 7 + 6</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> 22</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">This implies the total of 22 $ earned by the employee. and If we see the amount only for 3rd day, it comes out to be : ( x + 35 ) / 8 = ( 13 + 35 ) / 8 = (48 / 8 ) = 6</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">4. Two friends who have an eight-quart jug of water wish to share it evenly. They also have two empty jars, one holding five quarts, the other three. How can they each measure exactly 4 quarts of water ?</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>SOLUTION : </b></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Step-1:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">First of all water from 8-quart jug is poured into 3-quart jar, so now the values are :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">8-quart jug = 5-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">3-quart jar = 3-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">5-quart jar = 0-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Step-2 :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Now, water from 3-quart jar is poured into 5-quart jar, so now the values are :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">8-quart jug = 5-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">3-quart jar = 0-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">5-quart jar = 3-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Step-3:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Now again, water from 8 quart jug is poured into 3-quart jar, so now the values are :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">8-quart jug = 2-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">3-quart jar = 3-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">5-quart jar = 3-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Step-4:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Now, water from 3-quart jar is poured into 5-quart jar, Notice this time, since the 5-quart jar is left with only 2-quarts of capacity, therefore, 3-quart jar will be able to pour only 2-quarts of water, leaving 1-quart behind. So now the values are :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">8-quart jug = 2-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">3-quart jar = 1-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">5-quart jar = 5-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Step-5:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Now, the whole of water from 5-quart jar is poured back into 8-quart jug, which will set the values to :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">8-quart jug = 7-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">3-quart jar = 1-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">5-quart jar = 0-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Step-6:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Now, pour the water from 3-quart jar into 5-quart jar, making the values to :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">8-quart jug = 7-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">3-quart jar = 0-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">5-quart jar = 1-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Step-7:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Now again, fill the 3-quart jar by pouring water from 8-quart jug, making the values to :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">8-quart jug = 4-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">3-quart jar = 3-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">5-quart jar = 1-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Step-8:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Now, fill this 3-quart of water from 3-quart jar to 5-quart jar, and see it yourself that we have successfully divided 8-quarts of water into equal halves, so that both friends can get exactly 4-quarts of water. And the values can finally be seen as :</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">8-quart jug = 1-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">3-quart jar = 3-quart water</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">5-quart jar = 4-quart water </span><span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">5. The bin packing problem is an example of a wide set of problems. The task is to </span><span style="font-family: Arial, Helvetica, sans-serif;">find how many set sized bins are required to hold a number of differently sized </span><span style="font-family: Arial, Helvetica, sans-serif;">boxes. How many bins (10 units high) are required to contain the following boxes </span><span style="font-family: Arial, Helvetica, sans-serif;">(1,3,4 and 5 units high) ?</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>SOLUTION :</b></span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">Since, we've to put 1,3,4 and 5 units high boxes into 10 units high bins.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">As can be seen, we can put </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">1.) 1,4 and 5 units high boxes into 10 units high bin( all these boxes completely fit into bin w/o leaving any space behind )</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">2.) Now we're left with only 3 unit high box, which we've to put it into another 10 unit high bin, as we've no other option.</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-71434425959025751082013-08-23T22:39:00.002-07:002013-09-03T00:02:41.768-07:00PACKAGES IN JAVA<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">WHAT ARE PACKAGES IN JAVA<span style="font-weight: normal;"> </span>?</span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">When making any project in java, the project may constitute large number of classes and interfaces which are assigned to different development teams to code them. They place classes and interfaces having same category into packages. Packages are nothing but named directory /folder, where programmers keep classes and interfaces of same functionality.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">e.g.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Suppose, you've made different classes such as :</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Lion</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Tiger</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Peacock</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Vulture</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Car</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Bus</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">We can easily sense some kind of similarities among certain classes, such as:</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Lion and Tiger are <b>ANIMALS</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Peacock and Vulture are <b>BIRDS</b> </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Car and Bus are <b>VEHICLES</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Instead of keeping all these classes together, we would surely like to categorize classes of similar types together for well organization.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Therefore, we would put classes Lion and Tiger in ANIMAL PACKAGE.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Peacock and Vulture in BIRDS PACKAGE</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Car and Bus in VEHICLES PACKAGE</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">HOW DO WE CREATE PACKAGE IN JAVA ?</span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">When we create a class, we start by writing e.g.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">public class <name_of_class> {</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Data Members</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">/ / / / / / / / / / </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">/ / / / / / / / / </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Methods</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">/ / / / / / / / / </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"> / / / / / / / </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">}</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">So, we want the above class to belong to some package, we just have to write the 'package' keyword with a appropriate name given to that package as the first line of the program.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">e.g.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">package <name_of_package>;</span></div>
<div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">public class <name_of_class> {</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Data Members</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">/ / / / / / / / / / </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">/ / / / / / / / / </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Methods</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">/ / / / / / / / / </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"> / / / / / / / </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">}</span></div>
</div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>NOTE : </b>if we want our class to belong to some package, then we must begin our program with the package keyword and the name of the package as 1st line of the program.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">By doing this, a directory / folder gets created of the same name as that of package, in which our class get stored.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">WHAT ARE SUB-PACKAGES IN JAVA ?</span></h2>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">As name itself indicates, it is just another package inside the package.Lets take a scenario to understand the concept of sub-packages. Suppose we created a package called ANIMALS</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">and we have made classes such as :</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Lion</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Tiger</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Peacock</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Eagle</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Salmon</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Shark</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">It is absolutely clear that all the above classes are animals, but, if we look further, then we can sense that:</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Lion and Tiger are NON-FLYING ANIMALS</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Peacock and Eagle are FLYING ANIMALS</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Salmon and Shark are SEA ANIMALS</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Therefore, there arises a need to categorize them further. In-order to deal with this situation we need to put them in packages further, and all these newly formed packages will go into ANIMAL PACKAGE.</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Now, ANIMAL PACKAGE Contains 3 SUB-PACKAGES namely :</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">NON-FLYING ANIMALS ( containing classes : Lion and Tiger )</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">FLYING ANIMALS ( containing classes : Peacock and Eagle )</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">SEA ANIMALS ( containing classes : Salmon and Shark )</span></div>
<div>
<br /></div>
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">HOW DO WE CREATE SUB-PACKAGES IN JAVA ?</span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Suppose we have classes Tiger and Eagle. We know that both of these are animals, but at the same time both belong to a different category. Tiger belongs to Non flying category and Eagle belongs to Flying category. So, we need to put these classes into different sub-packages, and to do that, we begin the class code with 'package' keyword then name of the package then period(a dot) then the name of the sub-package. </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">e.g.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">package animals.</span><span style="font-family: Arial, Helvetica, sans-serif;">non_flying_animals</span><span style="font-family: Arial, Helvetica, sans-serif;">;</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">public class Tiger {</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">/ / / / /</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"> / / / </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">}</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">By doing so, the class Tiger will get stored in directory / folder structure: animals / flying_animals</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">To put Eagle class in another sub-package, we would insert tha package statement as :</span></div>
<div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">package animals.</span><span style="font-family: Arial, Helvetica, sans-serif;">flying_animals</span><span style="font-family: Arial, Helvetica, sans-serif;">;</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">public class Eagle {</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">/ / / / /</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"> / / / </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">}</span></div>
</div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">By doing so, the class Eagle will get stored in directory / folder structure as :</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">animals / flying_animals</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>NOTE : i) the name of the package should start with a small case.</b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>ii) the name must not contain blank spaces in between as in 'non flying animals', rather it should be written as 'non_flying_animals'.</b></span></div>
<div>
</div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-7648053227483176792013-08-23T15:15:00.001-07:002013-09-03T00:03:29.429-07:00INTRODUCTION TO ALGORITHMS<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr">
</div>
<h2 style="text-align: left;">
<b><span style="font-family: Arial, Helvetica, sans-serif;">WHAT IS AN ALGORITHM ?</span></b></h2>
<span style="font-family: Arial, Helvetica, sans-serif;">
An algorithm is a s What tep by step approach to solve any computational problem.</span><br />
<div dir="ltr">
</div>
<h2 style="text-align: left;">
<b><span style="font-family: Arial, Helvetica, sans-serif;">PROPERTIES OF AN ALGORITHM</span></b></h2>
1.) <span style="font-family: Arial, Helvetica, sans-serif;"><b>FINITENESS</b> : An algorithm must have finite number of steps, because if it has infinite number of steps(endless) then its of no use as it would never produce any expected output.<br />
2.) <b>DEFINITENESS</b> : An algorithm must be definite in nature i.e. all the steps must be unambiguous.<br />
3.) <b>INPUT </b>: An algorithm must at-least take an input to work on.<br />
4.) <b>OUTPUT</b> : An algorithm must produce at-least one or more outputs as final result.</span><br />
<div dir="ltr">
</div>
<h2 style="text-align: left;">
<b><span style="font-family: Arial, Helvetica, sans-serif;">ALGORITHM DESIGN TECHNIQUES</span></b></h2>
<span style="font-family: Arial, Helvetica, sans-serif;">
There are several approaches which are followed to have a computational solutions. These approaches are as follows :<br />
1.) <b>BRUTE FORCE TECHNIQUE</b> : in this technique, all the available attempts are made to get a perfect solution for the existing problem. An analogy can be made with locker, where all the combinations are tried to open the locker.<br />
2.) <b>DIVIDE AND CONQUER</b> : in this technique, a problem is divided into small modules and for each of those modules solutions are found recursively, which are further integrated to get the final desired output desired.<br />
3.) <b>GREEDY METHOD</b> : in this technique, the easiest solution is tried to be found out. An analogy can be made with the popular travel salesman problem, in which a sales man has to travel several cities and his target is to choose such a path which cost him least and he doesn't have to repeat any city which he has already travelled. The solution to this kind of problem lies in selecting the shortest path which connects all cities. This kind of approach is followed in greedy methods.<br />
4.)<b> DYNAMIC PROGRAMMING</b> : it is a design technique, in which a problem is divided into sub-problems and the subproblems are in turn dependent on each other for their solutions. The perfect example for this is the Fibonacci series, in which the subsequent number is found by adding the previous two numbers. e.g.<br />
0,1,1,2,3,5,8,1,3,2,1 </span> </div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-76858526270212208552013-08-07T06:49:00.000-07:002013-09-03T00:04:22.394-07:00CONVERTING ER DIAGRAMS TO RELATIONAL DATABASE<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: x-large;">An example of converting ER diagram to Tables</span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Here we've an image showing an ER-diagram :</span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-odKZXo6moZY/UgJLH2BXuBI/AAAAAAAAAOI/wLoJKG_-Ngc/s1600/ER+diagram.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="ER-diagram" border="0" height="358" src="http://3.bp.blogspot.com/-odKZXo6moZY/UgJLH2BXuBI/AAAAAAAAAOI/wLoJKG_-Ngc/s1600/ER+diagram.jpg" title="ER-diagram" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">ER-diagram</span></td></tr>
</tbody></table>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Our target is to implement this ER-diagram into SQL code, make tables and establish relationships between tables, satisfying the ER-diagram.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Below given are the CREATE TABLE statements, which are used to implement the above given ER-diagram.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"></span><br />
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1) Department table :</span></div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">
</span>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">create table department</span></div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">
<div>
(dept_id number not null primary key, </div>
<div>
dept_name varchar2(15) not null</div>
<div>
);</div>
<div>
<br /></div>
<div>
2) Branch table</div>
<div>
create table branch</div>
<div>
(branch_id varchar2(5) not null primary key, </div>
<div>
electives varchar2(10),</div>
<div>
dept_id number not null,</div>
<div>
constraint Department_Has_Branches</div>
<div>
foreign key (dept_id)</div>
<div>
references department(dept_id)</div>
<div>
);</div>
<div>
<br /></div>
<div>
3) Course table:</div>
<div>
create table course</div>
<div>
(course_id number not null primary key,</div>
<div>
course_name varchar2(10) not null,</div>
<div>
branch_id varchar2(5) not null,</div>
<div>
constraint Branch_Offers_Courses</div>
<div>
foreign key (branch_id)</div>
<div>
references branch(branch_id)</div>
<div>
);</div>
<div>
<br /></div>
<div>
4) Student table:</div>
<div>
create table student</div>
<div>
(stud_id number not null primary key, </div>
<div>
stud_name varchar2(30) not null,</div>
<div>
branch_id varchar2(5) not null,</div>
<div>
constraint Student_BelongsTo_Branch</div>
<div>
foreign key (branch_id)</div>
<div>
references branch(branch_id)</div>
<div>
);</div>
<div>
<br /></div>
<div>
5) Applicant table:</div>
<div>
create table applicant</div>
<div>
(app_id number not null primary key,constraint Student_SelectedAs_Applicant foreign key (app_id) to Student table</div>
<div>
references student(stud_id)</div>
<div>
);</div>
<div>
<br /></div>
<div>
6) applicant_AppliesFor_branch Table :</div>
<div>
create table applicant_AppliesFor_branch</div>
<div>
(app_id number not null, </div>
<div>
branch_id varchar2(5) not null,</div>
<div>
primary key (app_id, branch_id),</div>
<div>
constraint Student_AppliesFor_Branch</div>
<div>
foreign key (app_id)</div>
<div>
references applicant(app_id),</div>
<div>
constraint Branch_AppliedBy_Student</div>
<div>
foreign key (branch_id)</div>
<div>
references branch(branch_id)</div>
<div>
);</div>
</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-88720573043263153842013-08-04T06:02:00.000-07:002013-09-03T00:05:39.711-07:00SOLVED SQL QUERIES FROM INFOSYS LAB ASSIGNMENT part 1 of RDBMS<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;"><span style="font-size: x-large;">SQL queries based on Aggregate functions</span> :</span></span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;"></span></span><br />
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;"><span style="font-size: large;">1. List branchid and the number of courses offered by each branch.</span></span></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<br />
<div style="font-weight: normal;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large;">2. List branchid and the number of electives offered in each branch.</span></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<br />
<div style="font-weight: normal;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large;">3. List instructorid and number of different courses offered by those instructors.</span></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<div style="font-weight: normal;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large;">4. List the total strength of students staying in each Hostel.</span></span></div>
<span style="font-family: Arial, Helvetica, sans-serif;">
<div style="font-weight: normal;">
<span style="font-size: large;">5. List courseid and number of students registered in each course.</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">6. Count the number of students currently studying in branch B2.</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">7. Find the details of the total allocated hours for every branch.</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">8. List the instructorid who has taken at least 2 courses.</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;"><br /></span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">Inorder to solve the above queries, we would require several tables and the structure of those required tables to solve problems are as follows :</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;"><br /></span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">1. Course(course_id, course_name, semester, branch_id, electives, duration_hrs, all )</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">2. Instructors( inst_id, course_id )</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">3. Hostels( hostel_id, stud_id )</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">4. Registration( course_id, stud_id )</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">5. Student( stud_id, branch_id )</span></div>
<div style="font-weight: normal;">
<br /></div>
<div style="font-weight: normal;">
<span style="font-size: large;">Solutions :</span></div>
<div style="font-weight: normal;">
<br /></div>
<div style="font-weight: normal;">
<span style="font-size: large;">Query 1 :</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">List branchid and the number of courses offered by each branch.</span><br />
<span style="font-size: large;">Let's populate the 'course' table as follows: </span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-_XjaVfJ7Cvo/Uf426_EmmeI/AAAAAAAAANI/K6rir2XjypE/s1600/course+table1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Course table" border="0" height="384" src="http://1.bp.blogspot.com/-_XjaVfJ7Cvo/Uf426_EmmeI/AAAAAAAAANI/K6rir2XjypE/s640/course+table1.jpg" title="Course table" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small;">Course table</span></td></tr>
</tbody></table>
<span style="font-size: large;"><br /></span></div>
<div style="font-weight: normal;">
<div class="MsoNormal">
<br /></div>
</div>
<div style="font-weight: normal;">
<span style="font-size: large;"><br /></span></div>
<div>
<div style="font-weight: normal;">
<span style="font-size: large;">So, we are asked to list branch_ids and the number of courses associated with it. </span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">e.g. as can be seen in the table, </span></div>
<br />
<ul style="font-weight: normal; text-align: left;">
<li><span style="font-size: large;">B1 offers two courses( i.e. 101 and 103 )</span></li>
<li><span style="font-size: large;">B2 also offers two courses( i.e. 102 and 104 )</span></li>
</ul>
<div style="font-weight: normal;">
<span style="font-size: large;">It is pretty much clear that we require to retrieve two columns : </span><br />
<span style="font-size: large;"> 1) branch-id</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;"> 2) number of courses</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">As it is clear by looking at the table, we can't retrieve the <u>'number of columns'</u> directly from the <u>'course' table</u>, therefore, in-order to achieve that, we've to use aggregate function <u>COUNT()</u> clause on <u>'course_id' column</u>, which will count the number of courses associated with one brach_id and give us the number of courses.</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;"><br /></span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">Another thing is that, we've to group the retrieved data, in-order to prevent repetition of data. </span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">e.g. 'B1' comes twice in the <u>'branch_id' column</u></span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">and 'B2' also comes twice in the <u>'branch_id' column</u></span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">Therefore, to prevent this repetition in our retrieved data, we use <u>GROUP BY clause</u> .</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;"><br /></span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">SQL code :</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">SELECT branch_id, COUNT(course_id) AS number_of_students FROM course GROUP BY branch_id;</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;"><br /></span></div>
<div style="font-weight: normal;">
<span style="font-size: large;">-------------------------------------------------------------------------------------------------------------------------------</span></div>
<div style="font-weight: normal;">
<span style="font-size: large;"><br /></span></div>
<div style="font-weight: normal; text-align: left;">
<span style="font-size: large;">Query 2 :</span></div>
<div style="font-weight: normal; text-align: left;">
<span style="font-size: large;">List branchid and the number of electives offered in each branch.</span></div>
<div style="font-weight: normal; text-align: left;">
<span style="font-size: large;">This case is almost similar to the solution of Query 1, as now, we've to see for electives associated with branch_ids.</span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-_XjaVfJ7Cvo/Uf426_EmmeI/AAAAAAAAANI/K6rir2XjypE/s1600/course+table1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Course Table" border="0" height="240" src="http://1.bp.blogspot.com/-_XjaVfJ7Cvo/Uf426_EmmeI/AAAAAAAAANI/K6rir2XjypE/s400/course+table1.jpg" title="Course Table" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Course Table</td></tr>
</tbody></table>
<div style="font-weight: normal; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="font-weight: normal; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">CAUTION : the course_id values were unique in every row, but its not case with electives. We can see repeated values under 'electives' columns. Here in-order to prevent repetition of values , we'll use DISTINCT keyword.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">SQL code :</span></div>
<br />
<div>
<span style="font-size: large;">SELECT branch_id, COUNT(DISTINCT electives) AS elective_subjects FROM course GROUP BY branch_id;</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">----------------------------------------------------------------------------------------------------------------------------------</span></div>
<br />
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">Query 3 :</span></div>
<div style="text-align: left;">
<span style="font-size: large;">List instructorid and number of different courses offered by those instructors.</span></div>
<div style="text-align: left;">
<span style="font-size: large;">We've 'instructors' table as follows :</span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-7hAm4dgVph0/Uf5BX8aArbI/AAAAAAAAANY/JEMz45PlyRg/s1600/instructor.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Instructor Table" border="0" height="406" src="http://3.bp.blogspot.com/-7hAm4dgVph0/Uf5BX8aArbI/AAAAAAAAANY/JEMz45PlyRg/s640/instructor.jpg" title="Instructor Table" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Instructor Table</td></tr>
</tbody></table>
<div style="text-align: left;">
<span style="font-size: large;"> As can be clearly seen in the table, an instructor can have more than one course_ids associated with him and that's what we are asked to solve in query. i.e. we've to retrieve the instructor_id and the number of course_ids associated with him.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">SQL code:</span></div>
<div style="text-align: left;">
<span style="font-size: large;">SELECT inst_id, COUNT( course_id) FROM instructors GROUP BY inst_id;</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">-----------------------------------------------------------------------------------------------------------------------------------</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">Query 4 :</span></div>
<div style="text-align: left;">
<span style="font-size: large;">List the total strength of students staying in each Hostel.</span></div>
<div style="text-align: left;">
__________________________________</div>
<div style="text-align: left;">
<span style="font-size: large;">We've to use table : | hostels( hostel_id, stud_id ) |</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> ---------------------------------------</span></div>
<div style="text-align: left;">
<span style="font-size: large;">--------------------------------------</span></div>
<div style="text-align: left;">
<span style="font-size: large;">hostel_id | stud_id |</span></div>
<div style="text-align: left;">
<span style="font-size: large;">--------------------------------------</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> H1 | 401 |</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> H1 | 402 |</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> H2 | 403 |</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> H3 | 405 |</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> H3 | 406 |</span></div>
<div style="text-align: left;">
<span style="font-size: large;">--------------------------------------</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">As can be seen in the table, there can be more than one students in the same hostel, and that's what we are asked to find the number of students in each of the present hostel. Therefore, we'll put the 'stud_id' in the COUNT() aggregate function, which will give us the total number of students. And we'll use GROUP BY clause to group hostels.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">SQL code :</span></div>
<div style="text-align: left;">
<span style="font-size: large;">SELECT hostel_id, COUNT( stud_id ) AS total_students FROM hostels GROUP BY hostel_id;</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">-----------------------------------------------------------------------------------------------------------------------------------</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">Query 5 :</span></div>
<div style="text-align: left;">
<span style="font-size: large;">List courseid and number of students registered in each course.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">We've to use another table named Registration :</span></div>
<div style="text-align: left;">
<span style="font-size: large;">---------------------------------------</span></div>
<div style="text-align: left;">
<span style="font-size: large;">course_id | stud_id |</span></div>
<div style="text-align: left;">
<span style="font-size: large;">---------------------------------------</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> 101 | 401 |</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> 101 | 402 |</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> 102 | 401 |</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> 103 | 404 |</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> 104 | 405 |</span></div>
<div style="text-align: left;">
<span style="font-size: large;"> 104 | 406 |</span></div>
<div style="text-align: left;">
<span style="font-size: large;">---------------------------------------</span></div>
<div style="text-align: left;">
<span style="font-size: large;">As can be seen in the above table, more than one student can pursue same course. It means, with single course_id, there can be many stud_id associated with it. And that's what we are asked to find, i.e. group by the course_ids and number of students associated with those course_ids.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">Also, it can be seen, that a student can pursue more than one course at a time, as student with stud_id 401 is pursuing two courses with course_id 101 and 102.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">SQL code:</span></div>
<div style="text-align: left;">
<span style="font-size: large;">SELECT course_id, COUNT( stud_id ) FROM Registration GROUP BY course_id;</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">------------------------------------------------------------------------------------------------------------------------------------</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">Query 6 :</span></div>
<div style="text-align: left;">
<span style="font-size: large;">Count the number of students currently studying in branch B2.</span></div>
<div style="text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: large;">We've to use table named Student :</span></div>
<span style="font-size: large;">---------------------------------------</span><br />
<br />
<span style="font-size: large;">stud_id | branch_id |</span><br />
<span style="font-size: large;">---------------------------------------</span><br />
<span style="font-size: large;"> 401 | B1 |</span><br />
<span style="font-size: large;"> 402 | B2 |</span><br />
<span style="font-size: large;"> 403 | B2 |</span><br />
<span style="font-size: large;"> 404 | B4 |</span><br />
<span style="font-size: large;"> 405 | B2 |</span><br />
<span style="font-size: large;"> 406 | B3 |</span><br />
<span style="font-size: large;">---------------------------------------</span><br />
<span style="font-size: large;">This is almost similar to previous problem, as we are asked to find how many students took branch_id B2. It can be clearly seen from that there are 3 students who took branch_id B2.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">SQL code :</span><br />
<span style="font-size: large;">SELECT COUNT( stud_id ) FROM Student WHERE branch_id = 'B2';</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">------------------------------------------------------------------------------------------------------------------------------------</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">Query 7 :</span><br />
<span style="font-size: large;">Find the details of the total allocated hours for every branch.</span><br />
<span style="font-size: large;">We've to use table named 'course' as given follows :</span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/--pmOaE5nCX0/Uf5K5dPCseI/AAAAAAAAANo/uA6e3NdPiLw/s1600/course+table1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="384" src="http://4.bp.blogspot.com/--pmOaE5nCX0/Uf5K5dPCseI/AAAAAAAAANo/uA6e3NdPiLw/s640/course+table1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Course Table</td></tr>
</tbody></table>
<span style="font-size: large;">As can be seen, total hours for branch_id B1 are 48 + 52</span><br />
<span style="font-size: large;">So, we have to use SUM() aggregation function on column duration_hrs.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">SQL code :</span><br />
<span style="font-size: large;">SELECT branch_id, SUM( duration_hrs ) AS total_duration FROM course GROUP BY branch_id;</span><br />
<br />
<span style="font-size: large;">------------------------------------------------------------------------------------------------------------------------------------</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">Query 8 :</span><br />
<br />
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">
</div>
<br />
<div style="orphans: auto; text-align: left; text-indent: 0px; widows: auto;">
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<span style="font-size: large;">List the instructorid who has taken at least 2 courses.</span></div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<span style="font-size: large;"><br /></span></div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<span style="font-size: large;">Here, we have to use instructors table :</span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin-left: auto; margin-right: auto; text-align: center; text-transform: none; white-space: normal; word-spacing: 0px;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-qQMiKJKIXa4/Uf5MeKg61vI/AAAAAAAAAN4/aMlRd-68feY/s1600/instructor.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Instructor Table" border="0" height="406" src="http://2.bp.blogspot.com/-qQMiKJKIXa4/Uf5MeKg61vI/AAAAAAAAAN4/aMlRd-68feY/s640/instructor.jpg" title="Instructor Table" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Instructor Table</td></tr>
</tbody></table>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<span style="font-size: large;">It can be seen in the table that instructor with inst_id 1001 takes two courses with course_id 101 and 102. And we are asked to find those instructors those who have taken atleast two courses.</span></div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<span style="font-size: large;"><br /></span></div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<span style="font-size: large;">NOTE : since we have to use aggregate function COUNT(course_id ) in-order to count the number of courses associated with one instructor. So, it's a fact the counting is done at the run-time of SQL code, which means value is not already present anywhere in the table.</span></div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<span style="font-size: large;">And we have a condition that we must display only those instructors who has taken at-least 2 courses.</span></div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<span style="font-size: large;">This condition can be applied using 'HAVING' clause.</span></div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<span style="font-size: large;">Some of you may argue, Why can't we use 'WHERE' clause as a conditional test ?</span></div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<span style="font-size: large;">'WHERE' clause is always used for the already present columns of the table, whereas, 'HAVING' clause is used for the aggregate functions.</span></div>
<div style="margin: 0px;">
<br /></div>
<div style="margin: 0px;">
<span style="font-size: large;">One thing to note is that any column name appearing in the HAVING clause must also appear in the GROUP BY clause.</span></div>
<div style="margin: 0px;">
<span style="font-size: large;"><br /></span></div>
<div style="margin: 0px;">
<span style="font-size: large;">SQL code :</span></div>
<div style="margin: 0px;">
<span style="font-size: large;">SELECT inst_id, COUNT( course_id) AS total_courses FROM instructors GROUP BY inst_id HAVING COUNT(course_id) >= 2;</span></div>
<div style="margin: 0px;">
<span style="font-size: large;"><br /></span></div>
<div style="margin: 0px;">
<span style="font-size: large;">-----------------------------------------------------------------------------------------------------------------------------------</span></div>
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<span style="font-size: large;"><br /></span></div>
</div>
</div>
</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-43427810184058190622013-08-04T02:20:00.000-07:002013-08-04T07:29:28.303-07:00Strange Behaviour of 'GROUP BY' clause when used without 'ORDER BY' clause<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;">Using GROUP BY clause without using 'ORDER BY' clause</span></span></h2>
<div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"> <span style="font-size: large;">A table named HOSTEL(hostel_no NUMBER, no_of_stud NUMBER) is created and populated with values as follows : </span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">--------------------------------------</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">hostel_no| no_of_stud |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">--------------------------------------</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1001 | 124 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1001 | 234 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1002 | 97 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1002 | 134 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1003 | 234 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1004 | 123 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1004 | 89 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1001 | 67 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">-------------------------------------</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">When GROUP BY command is applied as : </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">SELECT hostel_no, sum(no_of_stud) as total_students FROM</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">HOSTELS GROUP BY hostel_no;</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">, and the output comes as:</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">--------------------------------------</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">hotel_no | total_students |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">--------------------------------------</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1003 | 234 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1001 | 425 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1002 | 231 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1004 | 212 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">--------------------------------------</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Now, the questions arise : </span></div>
<div>
<ul style="text-align: left;">
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Why the hostel_num 1003 came at the top ?</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"> Shouldn't it come at row number 3 ?</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"> What is the logic behind this kind of order ?</span></li>
</ul>
</div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">It is known, that GROUP BY clause consolidates the repetitive column values and group them together. Now the doubt here is: How it decides the order of displaying those values, as here, one would expect an output like this :</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">--------------------------------------</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">hotel_no | total_students |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">--------------------------------------</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1001 | 425 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1002 | 231 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1003 | 234 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">1004 | 212 |</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">--------------------------------------</span></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-55690573706683076882013-08-02T18:18:00.001-07:002013-09-03T00:06:06.259-07:00WEB TECHNOLOGIES<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;">What is web ?</span></span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">Web is a system of hypertext documents interlinked to each other.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;">Why is this Web required ?</span></span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;">The websites which we visit, e.g. facebook, wikipedia and many more, are accessed using Web. It makes information available anywhere in the World.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;">How do we use Web ?</span></span></h2>
<div>
<ul style="text-align: left;">
<li><span style="font-family: Arial, Helvetica, sans-serif;">Each and every resource present on the Web, which we also call as Web-pages, is given an unique and identifiable address called as <u>URL( Uniform Resource Locator)</u>.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">In-order to visit these web-pages, we need <u>Web Browsers</u> (e.g. google chrome, Internet explorer, mozilla-firefox, Opera, Safari ), where we write URL of the required web-page which we want to visit in the address bar of the Web Browser.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">Internet connection is required to carry this request(request for web-page) to the <u>Web</u> and bring response( Web-pages ) from the <u>Web</u> back to user.</span></li>
</ul>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-gUnMCFwSQeI/Uf0OT9_6svI/AAAAAAAAAMc/2LoWmVrFYQA/s1600/web-service-message-formats-1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Web browser sending request and receiving response from Web via internet" border="0" height="191" src="http://2.bp.blogspot.com/-gUnMCFwSQeI/Uf0OT9_6svI/AAAAAAAAAMc/2LoWmVrFYQA/s400/web-service-message-formats-1.png" title="Web browser sending request and receiving response from Web via internet" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Web-page request and response</span></td></tr>
</tbody></table>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
</div>
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;">Web- History and Evolution</span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;">In year 1989, Sir Tim Berners-Lee ( who is also known as the father of the WWW( World Wide Web) ) elaborated an IMS (Information Management System) that he built in 1980 which he named 'ENQUIRE' and wrote a proposal based on it.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;">In the year 1990, He wrote a more formal proposal to build a Hypertext Project called 'WWW i.e World Wide Web'. In this year Lee used a computer named 'NEXT' as a world's first web server.</span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-KbmwtJhyABU/Uf0S7LtTy1I/AAAAAAAAAMs/yUKRd1x2P_g/s1600/sir+tim+berner+lee+with+his+world's+first+web+server.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Tim Berners Lee with his world's first web server(NEXT)" border="0" height="489" src="http://4.bp.blogspot.com/-KbmwtJhyABU/Uf0S7LtTy1I/AAAAAAAAAMs/yUKRd1x2P_g/s640/sir+tim+berner+lee+with+his+world's+first+web+server.png" title="Tim Berners Lee with his world's first web server(NEXT)" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Tim Berners Lee with his world's first web server(NEXT)</span></td></tr>
</tbody></table>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-wxJdkzeFK9E/Uf0TbtiiUQI/AAAAAAAAAM0/0Lv9h3ssu3U/s1600/world's+first+web+server.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="World's first Web Server (NEXT)" border="0" height="480" src="http://1.bp.blogspot.com/-wxJdkzeFK9E/Uf0TbtiiUQI/AAAAAAAAAM0/0Lv9h3ssu3U/s640/world's+first+web+server.jpg" title="World's first Web Server (NEXT)" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">World's first Web Server (NEXT)</span></td></tr>
</tbody></table>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;"> </span></div>
<div>
<ul style="text-align: left;">
<li><span style="font-family: Arial, Helvetica, sans-serif;">In the same year i.e. 1990, he also wrote world's first web browser.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">In the year 1991, the WWW ( World Wide Web ) was made available to public.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">In the year 1993, the CERN announced </span><span style="font-family: Arial, Helvetica, sans-serif;">WWW ( World Wide Web ) free to all without any kind fees. This year was the beginning of the era of Web 1.0</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif;">The year 2003, with considerable modifications Web 2.0 launched.</span></li>
</ul>
</div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-weight: normal;"><br /></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-8623148317842592552013-08-02T18:17:00.001-07:002013-09-03T00:06:33.158-07:00SOFTWARE ENGINEERING<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Coming Soon.........</span></div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-64957004923376455082013-08-02T18:16:00.001-07:002013-08-07T07:00:59.684-07:00JAVA<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Coming soon.......</span></div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-66939880064467207012013-08-02T18:13:00.002-07:002013-09-03T00:07:10.821-07:00RELATIONAL DATABASE MANAGEMENT SYSTEMS<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>What is a database ?</b></span></h2>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">A database is an organized collection of interrelated data.<b> </b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Data has always been an useful entity, and when it becomes huge, then it becomes an urgency to store it somewhere, so that it can be referred or retrieved whenever required at some later point of time.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">In early ages, our predecessors carved on stones for the sake of records, then after the invention of paper, the information was started to be written on paper.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Now in the age of science and technology, we have developed such electronic gadgets, where the procedures of storing data are just a touch away.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">So, the proper formatted organization of large amount of data, which we store in memory devices, is referred to as DATABASE.</span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">e.g.</span></div>
<div>
<ul style="text-align: left;">
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Banks have to store a huge amount data about its customers and their accounts. So, the data about their Customers is an example of database.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Airlines ticketing services has store data about its passengers and their bookings. So that data about passengers is an example of database.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">All the email-id providers have to store huge amount of data of their users.So the data of those users forms the database.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Universities have to store information about their students and their corresponding courses etc. So, all the info related to the students forms the database.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">All the countries keeps the record of its citizens, which also forms the perfect example of database.</span></li>
</ul>
<h2 style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;">What is a Database Management System ?</span></span></h2>
</div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-weight: normal;"><br /></span></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large; font-weight: normal;">Database Management System is a set of programs ( i.e. a software ), which helps the user to store and manage data in a very organized way as per the requirements.</span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large; font-weight: normal;"><br /></span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large; font-weight: normal;">Let's say we run a showroom, and we want to store data about every that customer who visits our store, so that we can get to know about our customer base and moreover we can inform customers of special discounts and offers by retrieving their contact numbers from our Customer table stored in the database.</span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large; font-weight: normal;"> So, DBMS(i.e. Database Management Systems) help us in <u>creating databases</u>.</span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large; font-weight: normal;">A database so created may consists of so many <u>tables</u>, <u>relationships among those tables</u>, indexes, views etc.</span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large; font-weight: normal;"><br /></span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large; font-weight: normal;">Here in the above Scenario, we would like to create a <u>table named Customer</u>, which goes into the <u>database</u>, and then populate that table with the values of customers who visits our store.</span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large; font-weight: normal;"><u>The table</u> so created would further consists of <u>attributes</u>, say : name_of_customer, Address, Contact_no, No_of_visits, email_id etc.</span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large; font-weight: normal;">we will insert values of all the customers who visits our store corresponding to the attributes present in the customer table.</span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large; font-weight: normal;"> </span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large; font-weight: normal;"> Conclusively, DBMS is a software (there are many such DBMS softwares available on the internet, that can be downloaded, such as Oracle database 11g, MySql, Microsoft Sql Server etc. ), which we use to create( using SQL(Structured Query Language) coding ) databases as per our requirements.</span></span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: large; font-weight: normal;">In short, a DBMS allows us to perform :</span></span></div>
<div>
<ul style="text-align: left;">
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Reading operation</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Insertion operation (i.e. inserting values into the tables)</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Modification operation (i.e. changing values or table structures at some later point of time)</span></li>
</ul>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0tag:blogger.com,1999:blog-1077132650585766035.post-74735408695920484002013-08-02T18:12:00.002-07:002013-09-03T00:07:33.435-07:00OPERATING SYSTEMS<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
What is an Operating System ?</h2>
<div>
<span style="font-size: large;">If we speak in general terms, SOFTWARE is divided into 2 categories:</span></div>
<div>
<ol style="text-align: left;">
<li><span style="font-size: large;">Application software</span></li>
<li><span style="font-size: large;">System software</span></li>
</ol>
<div>
<h2 style="text-align: left;">
<span style="font-size: large;"><span style="font-weight: normal;">Application Software</span></span></h2>
<span style="font-size: large;">All the softwares which have specific functionality and which are little less complex than System Softwares, moreover they depend on System Softwares for their functioning and some of us use them in our daily lives, those are known as Application Softwares.</span></div>
</div>
<div>
<span style="font-size: large;">All the parts of above definition are very general and are written to make even a layman understand. </span></div>
<div>
<span style="font-size: large;">e.g. of </span></div>
<div>
<span style="font-size: large;">1) Softwares having specific functionalities are:</span></div>
<div>
<ul style="text-align: left;">
<li><span style="font-size: large;">Adobe photoshop(functions to work on pictures)</span></li>
<li><span style="font-size: large;">MS Word (functions as a writing editor)</span></li>
<li><span style="font-size: large;">Adobe Dreamweaver (functions as a website development tool)</span></li>
<li><span style="font-size: large;">Oracle database 11g (functions as a database management tool)</span></li>
</ul>
<div>
<span style="font-size: large;">2) Although they are also complex softwares, but as compared to System Softwares(windows 7,vista, 8, Machintosh), they are little less complex.</span></div>
</div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">3)If windows is not installed on your laptop/desktop, then, Is it possible to run any of the above stated Application Softwares on your laptop/desktop. This implies Application Softwares are dependent on System Softwares for their working. They can't run on bare hardware.</span><br />
<h2 style="text-align: left;">
<span style="font-weight: normal;">System Software</span></h2>
<div>
<span style="font-size: large;">Our laptop/Desktop consists of electronic parts, which we can see inside it's casing.We know that most of those electronic parts work on binary language (i.e. language of 0's and 1's ).</span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-o9_4I1nd4yc/UfzkNWuCDxI/AAAAAAAAAMM/1KtS45GgzrM/s1600/Operating+systems.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Operating System logos of various Companies" border="0" height="320" src="http://3.bp.blogspot.com/-o9_4I1nd4yc/UfzkNWuCDxI/AAAAAAAAAMM/1KtS45GgzrM/s320/Operating+systems.jpg" title="Operating system logos of various companies" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Operating system logos of various companies</span></td></tr>
</tbody></table>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Imagine if we've to directly work on hardware parts to get our work done, then we would have to remember large number of sequences of 0's and 1's, which is impossible. Therefore, we designed such softwares that deals with hardware behind the scenes and deals with us face to face, to get our work done.</span></div>
<div>
<span style="font-size: large;">So, the windows 7 , vista, xp, or 8 or machintosh( on apple laptops) which operates on hardware and interacts with us simultaneously , are called as System Softwares or OPERATING SYSTEMS.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">NOTE : since the usage of WINDOWS is so much that, it has become synonymous to OPERATING SYSTEM.</span></div>
<span style="font-size: large;"><br /></span>
</div>
<div>
<span style="font-size: large;"><br /></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/12658836089792874715noreply@blogger.com0