Introduction to Computers and C Programming - PowerPoint PPT Presentation

1 / 55
About This Presentation
Title:

Introduction to Computers and C Programming

Description:

Title: Introduction to Computers and C++ Programming Author: Master Last modified by: Qadri i. Mishael Created Date: 5/19/2002 3:30:33 AM Document presentation format – PowerPoint PPT presentation

Number of Views:93
Avg rating:3.0/5.0
Slides: 56
Provided by: master
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Computers and C Programming


1
Appendix Lab Manual for Programming Skills
2
How to work with VC
3
C PROGRAMING
  • To Make C program?
  • File ? New ? win 2 console application ?
  • write project name ? OK ? Finish ? OK
  • OR  
  • File ? New c source File ?
  • write File name ? OK

4
Start Page in Visual C 2008 Express Edition.
New Project tab
Start Page tab
Start Page links
Hidden windows
5
New Project dialog.
Template types
Visual C Win32 Console Application (selected)
Description of selected project
template (provided by Visual Studio)
Type in the project name
6
Win32 Application Wizard Application Settings
dialog.
7
Solution Explorer.
Solution Explorer with an open project
New tab displaying Welcome.cpp source code
Welcome.cpp in the Source Files folder of the
Welcome project
8
Standard toolbar in Visual Studio.
Solution Configurations
Navigate backward
New Project
Open File
Save All
Copy
Undo
Start
Save
Paste
Redo
Add Item
Cut
Navigate forward
Properties window
Toolbox window
Command window
Solution Platforms
Find in Files
Find
Solution Explorer
Object browser
Start Page
9
C PROGRAMING
  • To Compile the C program?
  •  
  • Build ? Compile.cpp
  • select compile icon ? from the menu bar or
  • press CTRL F7

10
C PROGRAMING
  • To Execute the C program?
  • 1-Bulid ? Execute .exe
  • 2- select Execute icon ? from the menu bar
  • 3-press CTRL F5

11
Symbols used in Writing Programs
  • opening curly bracket
  • closing curly bracket
  • hash sign or number sign (shift3)
  • ( ) small brackets
  • aaaa double quotes
  • aaaa single quotes
  • , comma
  • semicolon
  • void main( ) main function
  • // is used for making comment in one line
  • / is used for making comment in block form /

12
Unit 1
  • Objective To understand the concept of comments,
    input ,output
  • Statements and data types .
  • //PROGRAM-1 to demonstrate cout ... COMMENTS
  • // is used for making comment in program
  • includeltiostream.hgt //PREPROCESSOR
  • void main( ) // FUNCTION WITH RETURN
    TYPE VOID
  • //Beginning
  • coutltlt"WELCOME TO VC World "ltltendl
  • // cout IS AN OBJECT IN C, endl IS END OF
    LINE,
  • coutltltWarning! Get readyltltendl
  • // IS CALLED TERMINATOR.
  • // End

13
Unit 1
  • Program Explanation
  • include ltiostreamgt Include directive tells
    the compiler
  • Where to find information about input and output
    that are used in
  • Your program
  • cout (see-out) used for output to the monitor
  • ltlt is the insertion operator
  • \n causes a new line to be started on the
    monitor

14
Unit 1
  • //PROGRAM-2 to demonstrate cin cout (int,
    float,char)...
  • includeltiostream.hgt
  • void main( )
  • int a
  • float b
  • char c
  • coutltlt"ENTER AN INTEGER VALUE"ltltendl
  • cingtgta
  • coutltlt"ENTER A FLOAT VALUE"ltltendl
  • cingtgtb
  • coutltlt"ENTER A CHARACTER OR Alphabet"ltltendl
  • cingtgtc
  • coutltlt"INTEGER "ltltaltlt"\tFLOAT
    "ltltbltlt"\tCHARECTER "ltltcltltendl

15
Unit 1
  • Program Explanationcin gtgt a
  • cin (see-in) used for input from the keyboard
  • gtgt extracts data from the keyboard
  • Think of cin as a name for the keyboard
  • gtgt points from the keyboard to a variable where
    the data is stored

16
Unit 1
  • //PROGRAM-3 to find Sum and Average of two
    numbers.
  • includeltiostream.hgt
  • void main( )
  • folat a,b
  • float sum,avg
  • coutltlt"ENTER TWO NUMBERS"ltltendl
  • cingtgtagtgtb
  • sum a b
  • avg sum/2
  • coutltlt"SUM "ltltsumltlt"\n AVARAGE "ltltavgltltendl

17
Unit 1
  • //PROGRAM-4 to find Sum and Average of three
    numbers.
  • includeltiostream.hgt
  • void main( )
  • folat a,b,c
  • float sum,avg
  • coutltlt"ENTER THREE NUMBERS"ltltendl
  • cingtgtagtgtbgtgtc
  • sum a b c
  • avg sum/3
  • coutltlt"SUM "ltltsumltlt"\n AVARAGE "ltltavgltltendl

18
Uint 1
  • Check Your Programming skills
  • Write a C program to find the difference
    between two
  • Numbers?
  • Write a C program to find the product of three
    numbers?
  • Convert feet to inches given 1 feet 12 inches?

19
Unit 2
  • Objectives To implement the concept of operators
  • // PROGRAM-5 to find area of a circle.
  • includeltiostream.hgt
  • void main( )
  • float r,area
  • const float pi3.147
  • coutltlt"ENTER RADIUS OF CIRCLE"ltltendl
  • cingtgtr
  • area pirr
  • coutltlt"AREA OF CIRCLE "ltltarealtltendl

20
Unit 2
  • //Program -6 to display Pay slip of an employee
  • includeltiostream.hgt
  • void main ()
  • double GSal,NSal,ded,basic,da
  • const double Housing1000.00, TA500.00
  • coutltlt"Enter Basic Salary\n"
  • cingtgtbasic
  • coutltlt"Enter Deduction Amount\n"
  • cingtgtded
  • dabasic0.2
  • GSalbasicdaHousingTA
  • NSalGSal-ded

21
Unit 2
  • ..
  • coutltlt"\t\t\t\tBasic \t"ltltbasicltltendl
  • coutltlt"\t\t\t\tDA \t"ltltdaltltendl
  • coutltlt"\t\t\t\tHousing \t"ltltHousingltltendl
  • coutltlt"\t\t\t\tTravelling \t"ltltTAltltendl
  • coutltlt"\t\t\t\tGross salary \t"ltltGSalltltendl
  • coutltlt"\t\t\t\tDeduction \t"ltltdedltltendl
  • coutltlt"\t\t\t\tNet Salary \t"ltltNSalltltendlltltendllt
    ltendl

22
Unit 2
  • Check Your Programming skills
  • Write a C program to find the area of Square?
  • Write a C program to find the volume of Square?
  • Convert centigrade to Fahrenheit given
    F((C/5)9) 32?
  • Write a C program to create an invoice of item?

23
Unit 3
  • ObjectivesTo understand the concepts of
    conditional statements
  • Or control structure.( if else )
  • //Program -7 to find Number is MAX or MIN
  • includeltiostream.hgt
  • void main()
  • int a,b
  • coutltlt"Enter two numbers\n"
  • cingtgtagtgtb
  • if(agtb)
  • coutltltaltlt" is MAXIMUM "ltltbltlt" is MINIMUM\n"
  • else
  • coutltltbltlt" is MAXIMUM "ltltaltlt" is MINIMUM\n"

24
Unit 3
  • //Program -8 to find number is ODD OR EVEN
  • includeltiostream.hgt
  • void main()
  • int num
  • coutltlt"Enter a number\n"
  • cingtgtnum
  • if(num20)
  • coutltltnumltlt" is an Even Number\n"
  • else
  • coutltltnumltlt" is an Odd Number\n"

25
Unit 3
  • //Program -9 to find the Grade of students
  • includeltiostream.hgt
  • void main()
  • int mark
  • char grade
  • coutltlt"Enter mark"
  • cin gtgt mark
  • if(mark gt 90 mark lt 100 )
  • grade'A'
  • if(mark gt 80 mark lt 89 )
  • grade'B'

26
Unit 3
  • if(mark gt 70 mark lt 79 )
  • grade'C'
  • if(mark gt 60 mark lt 69 )
  • grade'D'
  • if(mark lt 60 )
  • grade'F'
  • coutltlt"Mark"ltlt"\t"ltlt"Grade"ltltendl
  • coutltltmarkltlt"\t"ltltgradeltltendl
  •  

27
Unit 3
  • Check Your Programming Skills
  • Write a C program to find the largest among
    three numbers by
  • using if-else?
  • Write a C program to find whether the given
    number is Prime
  • number or not by using if-else?
  • Write a C program to find whether the given
    number is
  • divisible of 5 or not by using if-else?

28
Unit 4
  • ObjectivesTo understand the concepts of
    conditional statements
  • Or control structure.( Switch Case )
  • //Program-10 to check the day of week by using
    SWITCH-CASE
  • includeltiostream.hgt
  • void main()
  • int x
  • coutltlt"Enter number"ltltendl
  • cingtgtx
  • switch(x)
  • case 1
  • coutltlt"Saturday"ltltendl
  • break

29
Unit 4
  • case 2
  • coutltlt"Sunday"ltltendl
  • break
  • case 3
  • coutltlt"Monday"ltltendl
  • break
  • case 4
  • coutltlt"Tuesday"ltltendl
  • break
  • case 5
  • coutltlt"Wednesday"ltltendl
  • break

30
Unit 4
  • case 6
  • coutltlt"Thursday"ltltendl
  • break
  • case 7
  • coutltlt"Friday"ltltendl
  • break
  • default
  • coutltlt"Error"ltltendl

31
Unit 4
  • // Program- 11 Menu driven program ( , , - ,
    ) using
  • switch case statement
  • includeltiostream.hgt
  • void main()
  • int n1, n2
  • char op
  • coutltlt"Enter first number" cin gtgt n1
  • coutltlt"Enter second number" cin gtgt n2
  • coutltlt"Enter operator(, /, -)" cin gtgt op
  • switch (op)
  • case 'coutltltn1ltltopltltn2ltlt""ltlt(n1n2)ltltendlbr
    eak

32
Unit 4
  • ..
  • case '/coutltltn1ltltopltltn2ltlt""ltlt(n1/n2)ltltendlbre
    ak
  • case 'coutltltn1ltltopltltn2ltlt""ltlt(n1n2)ltltendlbre
    ak
  • case '-coutltltn1ltltopltltn2ltlt""ltlt(n1-n2)ltltendlbre
    ak
  • defaultcoutltlt"Invalid oprator"ltltendlbreak

33
Unit 4
  • Check Your Programming Skills
  • Write a C program to find month of years by
    using a
  • switch case statement?
  • Write a menu driven program to calculate
    different currency
  • Conversions?

34
Unit 5
  • ObjectivesTo understand the concepts of
    conditional statements
  • Or control structure.( Loops FOR, WHILE, DO
    WHILE )
  • // Program-12 to print natural numbers from 1 to
    30 using FOR loop
  • include ltiostreamgt
  • void main()
  • int i
  • for (i0ilt30i)
  • coutltlt" "ltlt"i"
  • coutltltiltltendl

35
Unit 5
  • // Program-13 to print natural numbers from 1
    to 30 using
  • WHILE loop
  • includeltiostream.hgt
  • void main()
  • int a1
  • while(alt30)
  • coutltltaltltendl
  • a

36
Unit 5
  • // Program-14 to print natural numbers from 1
    to 30 using
  • DO WHILE loop
  • includeltiostream.hgt
  • void main()
  • int a1
  • do
  • coutltltaltltendl
  • a
  • while(alt30)

37
Unit 5
  • //Program -15 to display first 10 Odd numbers
    using FOR loop
  • include ltiostreamgt
  • void main()
  • int i
  • for (i1ilt20ii2)
  • coutltlt" i"ltltiltltendl

38
Unit 5
  • //Program-17 to display first 10 Odd numbers
    using
  • WHILE loop
  • includeltiostream.hgt
  • void main()
  • int a1
  • while(alt20)
  • coutltltaltltendl
  • aa2

39
Unit 5
  • //Program-18 to display first 10 Odd numbers
    using
  • DO WHILE loop
  • includeltiostream.hgt
  • void main()
  • int a1
  • do
  • coutltltaltltendl
  • aa2
  • while(alt20)

40
Unit 5
  • //Program-19 to find the Factorial of Number
    using do while loop
  • includeltiostream.hgt
  • void main()
  • int n,i1,fact1
  • coutltlt" enter the number "
  • cingtgtn
  • if(ngt0)
  • do
  • factfacti
  • i

41
Unit 5
  • ..
  • while(iltn)
  • coutltlt"fact"ltltfactltlt"\n"

42
Unit 5
  • Check Your Programming Skills
  • Write a C program to display first 10 even
    numbers using
  • For loop?
  • Write a C program to display first 10 even
    numbers using
  • WHILE loop?
  • Write a C program to display first 10 even
    numbers using
  • DO WHILE loop?
  • Write a C program to find the Factorial of
    Number using
  • For loop?
  • Write a C program to print all prime numbers
    between two
  • limits by using do while loop?

43
Unit 6
  • ObjectivesTo understand the concepts of nested
    loops
  • // Program-20 Program to display stars in a
    triangle shape
  • include ltiostreamgt
  • void main()
  • int i,j,k,n,m
  • coutltlt"Enter a number"
  • cingtgtn
  • mn
  • for(i0iltni) //
  • //
  • for(j0jltij) //
  • coutltlt" "

44
Unit 6
  • ..
  • for(k0kltmk)
  • coutltlt" "
  • coutltltendl
  • m--

45
Unit 6
  • Check Your Programming Skills
  • Write a C program to display different types of
    triangles
  • Write a C program to display following
    patterns?

46
Unit 7
  • ObjectivesTo understand the concept of arrays
  • // Program-21 program to store 5 numbers in an
    array then
  • print them
  • includeltiostream.hgt
  • void main()
  • int a5,i
  • for(i0ilt5i)
  • coutltlt"enter any Number "ltltendl
  • cingtgtai

47
Unit 7
  • ..
  • coutltlt"The Elements are as below "ltltendl
  • for(i0ilt5i)
  • coutltltailtltendl

48
Unit 7
  • // Program-23 program using arrays for checking
    Maximum
  • number and Minimum number among elements
  • include ltiostreamgt
  • void main()
  • int a8,i,max,min
  • coutltlt"Enter 8 number"ltltendl
  • for(i0ilt8i)
  • cingtgtai
  • maxmina0

49
Unit 7
  • ..
  • for(i0ilt8i)
  • if (aigtmax)
  • maxai
  • if (ailtmin)
  • minai
  • coutltlt"Maximum number"ltltmaxltltendl
  • coutltlt"Minimum number"ltltminltltendl

50
Unit 7
  • Check Your Programming Skills
  • Write a C program to store 5 numbers in an
    array then print
  • them in reverse order?
  • Write a C program to display following
    patterns?

51
Unit 8
  • ObjectivesTo implement the concept of function.
  • // Program-24 to Add two numbers using function
  • include ltiostreamgt
  • int add(int x, int y)
  • void main()
  • int a, b
  • coutltlt" Enter value of a "
  • cingtgta
  • coutltlt" Enter value of b "
  • cingtgtb
  • add(a,b)

52
Unit 8
  • ..
  • int add(int x, int y)
  • int res
  • res xy
  • coutltlt" Sum "ltltresltltendl
  • return res

53
Unit 8
  • // Program-25 to find the factorial of a number
    by using function
  • includeltiostream.hgt
  • int fact(int)
  • void main()
  • int x,f
  • coutltlt"enter the number"
  • cingtgtx
  • ffact(x)
  • coutltlt"The factorial"ltltf

54
Unit 8
  • .
  • int fact(int a)
  • int i,f1
  • for(i1iltai)
  • ffi
  • return f

55
Unit 8
  • Check Your Programming Skills
  • Write a C program to calculate difference of
    two numbers by
  • using functions?
  • Write a C program to calculate the
    Multiplication of two
  • numbers by using functions?
  • Write a C program to calculate the square of
    any integer by
  • using functions?
  • Write a C program to calculate the square root
    of any integer
  • by using functions?
Write a Comment
User Comments (0)
About PowerShow.com