Docsity

Introduction to Computer Programming C++, Study Guides, Projects, Research of C programming

Partial preview of the text

Download Introduction to Computer Programming C++ and more Study Guides, Projects, Research C programming in PDF only on Docsity!

FCS&E, GIK Institute Topi, Pakistan Page 1 of 94

Faculty of Computer Science and Engineering Faculty

Introduction to computing and Programming Lab

CS-101L

Ghulam Ishaq Khan Institute of Engineering

Sciences and Technology, Topi.

Introduction to Computing and Programming Lab Manual

  • Lab#1: GIKI email Service and FCSE Course website Table of Contents
  • Lab#2: Learning Different Number Systems
  • Lab#3: Introduction to C/C++ Basics
  • Lab#4: Variables, inputs/outputs and Arithmetic Operators
  • Lab#5: Decision Control Statements
  • Lab#6: While Loop and Nested While Loop
  • Lab#7: For Loop
  • Lab#8: Switch and Case Statements
  • Lab#9: Functions Part
  • Lab#10: Functions Part
  • Lab#11: Arrays
  • Lab#12: Pointers
  • References…… ………………………………………………………………………………………………………………………………….…..

Using Internet via Internet Explorer

Internet facility is available on all the Computers of PC-LAB for almost 15 hrs per day (See PC-Lab working hours at the entrance of the Lab). You can use Internet at your room in the Hostel (if you find problem with your room Network/Internet you can contact Netronix or Hardware Workshop located in FCSE). To use Internet please click on the Internet Explorer Icon on your desktop. The homepage will be displayed. If you see an error message as shown in the figure below. It means that you need to configure your internet explorer according to GIKI Internet service. To do this you should follow the following steps.

Click on Tools and then on Internet Option. You will see a screen like this

Click on connection and then on LAN Settings. Type 192.168.100.13 in the Address Box. If this is not working then change it to 192.168.100.14. and click on OK button. Now click refresh on the browser. If you still have a problem, then consult the lab staff.

Using GIKI Email

GIKI Email is the primary source of communications on the campus. You can also your email to contact people outside the Institute. Your email addresses have already been created and are ready to use. Your email identity is your registration number preceded by an alphabet “u” i.e.u2012XXX Sample email address for 2012001 looks like [email protected]. To use this email you need a password that is available at the PC Lab desk with the laboratory assistants. They will give you your email passwords. You cannot collect the password for your friend. One must have come to collect his/her own password from the Lab assistants. In order to access your email you need to switch on your PC and log into windows and then click on the Internet Explorer icon on your PC’s desktop and type mail.giki.edu.pk or 192.168.100.5 You will see a screen like the following.

Then click on change password

After changing the password please make sure to remember the new password as the Lab Assistants cannot change your password again. In that case you need to contact the CPU Room in FCSE. Now your email address has been configured and ready for use. You can explore the other options and learn them as an exercise.

FCSE Course Website

To facilitate the students enrolled in FCSE courses, a separate local website is maintained for students to access the course material, participate in academic discussions, download relevant course lectures, submit assignments and read up to date news and announcements about various courses. The FCSE website can be accessed using internet explorer with the following address http://192.168.1. First of all you have to make an account and then after “login” you can access the sites of those courses which you have registered for. Open Internet Explorer  write 192.168.1.21 in address bar 

click on login (Top left), you will see the following

Press the login button

How to download Files form course website:

First of all login to course website, Click on yours desired course. The weekly break for that course will be displayed. Access the current week. You will find some files. Click on the files and save it on your computer. How to Upload Assignments on Course Website:

First of all access the course website and current week. You will find a symbol like click on it and you will be directed to a new page. Upload yours file and click save.

FCSE Software Server

192.168.100.4 is the ip address of the computer which has almost all the necessary soft wares that have to be used in GIKI. You will go to the server by click on start button at the task bar  run  enter the ip and press enter key. In resources folder you can get all the softwares. Please note that don’t install any software directly from software server (100.4). First copy it to your local PC and then install it from there.

What is search engine?

Search engine is basically a website which stores information about different other websites, so search engine will help you to access a website of yours own interest without knowing the address of that specific website. Google is a powerful search engine. It searches for the web pages which contains the information which you have provided in the search option. Sometime the information provided by the search engine is irrelevant. Try to search with your search option enclosed in double quotes (“”) and without it.

Lab#2: Learning Different Number Systems

Dear Students today’s lab exercise will result in the following outcomes. Please ensure you complete all the steps yourself and don’t indulge in any kind of cross talk or interference in the work of other students.

Aim of Today’s Lab  To learn Different Number Systems

  • Inter conversion of different number Systems  To learn about Flow Chart
  • What is Flow Chart
  • Symbols which are using in flow Chart  To learn about Algorithms
  • What is an Algorithms
  • Different Examples  To learn about the Hardware of the Computer System
  • CPU
  • RAM
  • Mother Board etc

Number Systems

Digital computers are the machines which respond numbers, all the data and instruction must therefore be represented in a numeral format. Thus number systems are very important to understand because a computer understands numbers only. The binary system ahs been found to be the most natural and efficient system for modern digital machine.

The Decimal Number system: (Base 10 )

This is the system we are used to in our everyday lives. The decimal number system consists of 10 digits form 0 to 9. (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

The Binary Number System: (Base 2)

The Binary Number System consists of two digits 0 and 1.

The Octal Number System: (Base 8)

The Octal Number System consists of 8 digits 0, 1, 2, 3, 4, 5, 6 and 7.

The Hexadecimal Number System: (Base 16)

The Hexadecimal Number System consists of 16 digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F. The alphabets A, B, C, D, E and F are used to represent decimal numbers 10, 11, 12, 13, 14,

Number Systems Chart

Decimal Binary Octal Hexadecimal 0 0000 0 0 1 0001 1 1 2 0010 2 2 3 0011 3 3 4 0100 4 4 5 0101 5 5 6 0110 6 6 7 0111 7 7 8 1000 10 8 9 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F 16 10000 20 10

Number Conversion

We in general use decimal number system in our daily life. However, binary number system are suitable for use in digital computers. Other number systems are used for programming/coding and data storage purposes. Thus inter-conversion of numbers from one number system into other number system becomes important for computation and data processing in digital computers.

Convert the Hexadecimal number (3F8A) 16 (3F8A) 16 = 3 * 16^3 + 15 * 16^2 + 8 * 16^1 + 10 * 16^0 = 3 * 4096 + 15 * 256 + 8 * 16 + 10 * 1 = 12288 + 3840 + 128 + 10 = (16266) 10

Decimal to Hexadecimal Conversion

Example-2. Convert the decimal number (694) 10 into its hexadecimal number.

694/16 = 43 with a remainder of 6 43/16 = 2 with a remainder of 11 2/16 = 0 with a remainder of 2

Hence (694) 10 = (2B6)H

Binary to Octal Conversion

  • Highest symbol is 7
  • 7 in Binary is 111
  • Therefore, the largest Binary grouping in octal consists of 3 bits.
  • Conversion is achieved by breaking Binary into groups of 3 bits, starting from the Right side, and finding the Octal equivalent Examples-2. a) (101110010100)B = (_________)o b) (1101110111101) 2 = (______) 8

101 | 110 | 010 | 100 001 | 101 | 110 | 111 | 101

↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ 5 6 2 4 1 5 6 7 5 Hence (101110010100)B = (5624)o and (1101110111101) 2 = (15675) 8 Note: In example b, we add two zeros to the left so that the grouping is 3 bits. This does not affect the original number.

Octal to Binary Conversion

Here we reverse the process shown for Binary to Octal conversion. Example-2. (45)O = (__________)B

4 = 5 = 101 Hence (45)O= (100101)B

Binary to Hexadecimal

  • Highest symbol is F (15)
  • 15 in Binary is 1111
  • Therefore, the largest Binary grouping is Hexadecimal consists of 4 bits.
  • Conversion is achieved by breaking Binary into groups of bits, starting from the Right side, and finding the Hexadecimal equivalent. Example-2.

a) (101110111110) 2 = (_____ ) 16 b) (10010100010)B=(_______)H

B B E 4 A 2

Hence (101110111110) 2 = (BBE) 16 and (10010100010)B = (4A2)H

Hexadecimal to Binary Conversion

Here we reverse the process shown for Binary to Hexadecimal conversion. Example-2. (B1A) 16 = (________) 2

B = 1011 1 = 0001 Hence (B1A) 16 (1011 0001 1010) 2 A = 1010

Flowcharts

A flowchart (also spelled flow-chart and flow chart) is a schematic representation of a process. They are commonly used in business/economic presentations to help the audience visualize the content better, or to find flaws in the process. Examples include instructions for a bicycle's assembly, an attorney outlining a case's timeline, diagram of an automobile plant's work flow, the decisions to be taken on a tax form, et cetera. Generally the start point, end points, inputs, outputs, possible paths and the decisions that lead to these possible paths are included. Flow-charts can be created by hand or manually in most office software, but lately specialized diagram drawing software has emerged that can also be used for the purpose, such as Visio, OpenOffice.org Draw and Dia.

Meaning of a Flowchart

A flowchart is a diagrammatic representation that illustrates the sequence of operations to be performed to get the solution of a problem. Flowcharts are generally drawn in the early stages of formulating computer solutions. Flowcharts facilitate communication between programmers and business people. These flowcharts play a vital role in the programming of a problem and are quite helpful in understanding the logic of complicated and lengthy problems. Once the flowchart is drawn, it becomes easy to write the program in any high level language. Often we see how flowcharts are helpful in explaining the program to others. Hence, it is correct to say that a flowchart is a must for the better documentation of a complex program.

Guidelines for Drawing a Flowchart

± plus or minus = equal to

greater than < less than ≥ greater than or equal to ≤ less than or equal to ≠ not equal YES or Y NO or N TRUE or T FALSE or FF

Few Examples on Flowcharting

Now we shall present few examples on flowcharting for proper understanding of this technique. Example 2. Draw a flowchart to find the sum of first 50 natural numbers.

Example 2. Draw a flowchart for computing factorial N (N!) Where N! = 1 x 2 x 3 x …… N

al-Khwarizmi

Algorithm History

The word algorithm comes ultimately from the name of the 9th- century mathematician Abu Abdullah Muhammad bin Musa al-Khwarizmi. The word algorism originally referred only to the rules of performing arithmetic using Arabic numerals but evolved into algorithm by the 18th century. The word has now evolved to include all definite procedures for solving problems or performing tasks. The first case of an algorithm written for a computer was Ada Byron's notes on the analytical engine written in 1842, for which she is considered by many to be the world's first programmer. However, since Charles Babbage never completed his analytical engine the algorithm was never implemented on it.

Definition

An algorithm is a finite set of well-defined instructions for accomplishing some task The concept of an algorithm is often illustrated by the example of a recipe, although many algorithms are much more complex; algorithms often have steps that repeat (iterate) or require decisions (such as logic or comparison) until the task is completed. If an algorithm is flawed or not appropriate to the problem it will not solve the problem even if we use it efficiently.. For example, performing the potato salad algorithm will fail if there we try to use it to prepare apple salad even if all the motions of preparing the salad are performed. Example: 2. Problem: Write an algorithm to find the sum of two numbers Solution:

  1. Input first number
  2. Store the number in a
  3. Input the second number
  4. Store the second number in b
  5. Calculate the sum using a + b
  6. Store the sum in c
  7. Print the sum stored in c

Example: 2.14 (Non Computer)

1. Brush the teeth

  1. Wash the face
  2. Comb the hair
  3. Smile in mirror
  4. Go to CS101 Class