Pitt INFSCI 0012 - Introduction to Programming (9 pages)

Previewing pages 1, 2, 3 of 9 page document View the full content.
View Full Document

Introduction to Programming



Previewing pages 1, 2, 3 of actual document.

View the full content.
View Full Document
View Full Document

Introduction to Programming

58 views


Pages:
9
School:
University of Pittsburgh
Course:
Infsci 0012 - Introduction to Programming
Unformatted text preview:

IS 12 1 IS12 Introduction to Programming Date February 5 2003 IS 12 Increment and Decrement Operators b increments variable b by 1 and then uses the value in b b uses the variable b and then increments b by 1 b decements variable b by 1 and then uses the value in b b uses the variable b and then decrements b by 1 Sample Program using Increment and Decrement Operators include stdio h int main int num 25 printf d n num printf d n num postincrement printf d n n num num 25 printf d n num printf d n num preincrement printf d n num return 0 When writing increment and decement operators the following statements are the same countOfStudents countOfStudents 1 countOfStudents 1 countOfStudents Other examples include x 9 is the same thing as x x 9 d 10 is the same thing as d d 4 y 2 is the same thing as y y 2 g 6 is the same thing as g g 6 m 8 is the same thing as m m 8 2 IS 12 3 Compound If statement Logical Operators The logical operators are and or not These are used to determine relationships Zero results in false and nonzero is true when comparing internally and truth table is expression one 0 0 nonzero nonzero expresson two expression 1 expression two 0 nonzero 0 nonzero 0 0 0 1 Example if fullTime 1 yearService 10 yearServiceOverTen All conditions must be true for the condition to be considered true or truth table is expression one 0 0 nonzero nonzero expresson two 0 nonzero 0 nonzero expression 1 expression two 0 1 1 1 Example if semesterAverage 90 0 finalGrade 90 0 printf Student Grade is an A n Only one of the conditions must be true for the condition to be considered true not truth table is logical negation expression 0 nonzero expresson 1 0 Example if grade someValue printf The next grade is f n grade IS 12 More Sample Programs for Review Sample program showing two numbers in which we will get the sum product quotient and modulus of include stdio h int main int x y printf Enter two numbers scanf d d x y printf The sum is d n x y printf The product is d n x y printf The difference is d n x y printf The quotient is d n x y printf The modulus is d n x y return 0 Sample program to show whether a number is odd or even include stdio h int main int integerNum printf Input an integer scanf d integerNum if integer 2 0 printf d is an even integer n integerNum if integer 2 0 printf d is an odd integer n integerNum return 0 4 IS 12 Sample Sales Program include stdio h int main double sales wage printf Enter sales in dollars 1 to end scanf lf sales while sales 1 0 wage 200 00 0 09 sales printf Salary is 2f n n wage printf Enter sales in dollars 1 to end scanf lf sales return 0 Sample Payroll Program include stdio h int main void double hours rate salary printf Enter number of hours worked 1 to end scanf lf hours while hours 1 0 printf Enter hourly rate of the worker 00 00 scanf lf rate if hours 40 salary hours rate else salary 40 00 rate hours 40 00 rate 1 5 printf Salary is 2lf n n salary printf Enter number of hours worked 1 to end scanf lf hours return 0 5 IS 12 Sample Program using For include stdio h int main void int row col for row 1 row 10 row for col 1 col row col printf printf n printf n for row 10 row 1 row for col 1 col row col printf printf n return 0 6 IS 12 Sample program using if instead of switch include stdio h int main void int grade int aCount 0 bCount 0 cCount 0 int dCount 0 fCount 0 printf Enter the letter grades printf Enter the EOF character to end input n while grade getchar EOF if grade A grade a aCount else if grade B grade b bCount else if grade C grade c cCount else if grade D grade d dCount else if grade F grade f fCount else if grade n grade empty body else printf Incorrect letter grade entered printf Enter a new grade n printf nTotals for each letter grade were n printf A d n aCount printf B d n bCount printf C d n cCount printf D d n dCount printf F d n fCount return 0 7 IS 12 8 INTRODUCTION TO PROGRAMMING INFSCI 0012 Wednesday s 6 00 p m Information Science Building 404 Group Work Assignment Develop a detailed algorithm and program solution to the following problem A program is needed to determine if a department store customer has exceeded the credit limit on a charge account For each customer the following facts are available a b c d e Account number an integer Balance at the beginning of the month Total of all items charged by this customer this month Total of all credits applied to this customer s account this month Allowed credit limit The program should input each of these facts calculate the new balance beginning balance charges credits and determine if the new balance exceeds the customer s credit limit For those customers whose credit limit is exceeded the program should display the customer s account number credit limit new balance and the message Credit limit exceeded Sample Run Enter account number 1 to end 100 Enter beginning balance 5394 78 Enter total charges 1000 00 Enter total credits 500 00 Enter credit limit 5500 00 Account 100 Credit limit 5500 00 Balance 5894 78 Credit Limit Exceeded Enter account number 1 to end 200 Enter beginning balance 1000 00 Enter total charges 123 45 Enter total credits 321 00 Enter credit limit 1500 00 Enter account number 1 to end 300 Enter beginning balance 500 00 Enter total charges 274 73 Enter total credits 100 00 Enter credit limit 800 00 Enter account number 1 to end 1 Reference Deitel and Deitel Prentice Hall IS 12 9 C Student Review using Knowledge Tree Developed by Peter Brusilovsky and graduate doctorate students in Information Science http www2 sis pitt edu peterb 0012 032 tools html Create an account and view information in the knowledge tree related to C There are many explanations that will help you in understanding the C programming language Reference used Deitel H and Deitel P 2001 C How to Program Third Edition NJ Prentice hall


View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Introduction to Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to Programming and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?