CSC 155 Computer Science I Week 1 An Overview of Computers and Programming Languages Lecture Notes Student Name Types of Computer Systems Here are the classes of computers. Type Description Microcontrollers or Embedded Computers The smallest class of computers. Are the type of small computer processors that are found in small machines and appliances, such as a microwave oven, pacemakers, smart cards and RFIDs. Microcomputers Minicomputers Are typically larger in size than a microcomputer. Another name for typical home PC's. Are manufactured as desktops, as towers or as laptops. A Notebook can also be classified as a Microcomputer, as well as Tablet PCs. How about palm pilots? Are not as popular as they used to be. Mainframes Are typically used in larger business enterprises. Are competitive computer systems with LANs or Local Area Networks. Supercomputers Need to be stored in special refrigerated rooms. Are used primarily by scientists and engineers to perform important computations. Dept of Defense, various universities own supercomputers. © Copyright 2011 by P.E.P. 1 CSC 155 Computer Science I Week 1 An Overview of Computers and Programming Languages Lecture Notes Student Name What is a Computer Program? A computer program is a set of instructions which tells a computer to perform a particular task. What is an Algorithm? An algorithm is a step - by - step procedure to solve a problem or to perform some task. As an example of a set of instructions, consider the following scenario: Making popcorn in a microwave oven. • • • • • • • • • Secure a bag of microwaveable popcorn. Read the instructions on the popcorn bag. Place popcorn bag on a dish such that the bag is oriented properly upward ( this side down ) Place dish with popcorn into microwave oven (open microwave oven door first ) Next, depress the popcorn button on the microwave ( make sure the oven’s door is closed ) Wait for popcorn to be properly prepared. When bell rings, open the oven and carefully grab that hot popcorn bag. Commence consumption of contents of the popcorn bag, avoid biting an any un - popped kernels. Most likely you will have to share said contents of popcorn bag with a relative or a friend. What are the Steps to Program? (1) (2) (3) (4) (5) (6) Define the Problem Design a Solution Develop an Algorithm Code the Program Test the Program Document the Program What is IPOS? The IPOS Model is Input, Process, Output and Storage. This is the model that many programmers use to construct computer programs. © Copyright 2011 by P.E.P. 2 CSC 155 Computer Science I Week 1 An Overview of Computers and Programming Languages Lecture Notes Student Name What is Pseudocode? Not actually a programming language, but English - like statements which are used to develop an algorithm or a program. Example of Pseudocode Pseudocode to find the average of 5 numbers Set the sum of the values to zero Set a count of the values to zero Do as long as the count is less than or equal to 5 Read the next data value Add this data value to the sum Add 1 to the count Divide the sum by 5 to compute the average Print the average Example of Pseudocode Pseudocode to compute employee net pay Enter the employee’s name Enter the number of hours worked Enter the hourly wage If number of hours worked <= 40 then gross pay = hours worked * hourly wage If the number of hours worked > 40 then gross pay = hours worked * hourly wage + 1.5 * ( hours worked – 40 ) * hourly wage Enter the taxes net pay = gross pay * taxes Print the employee’s name and the net pay What is a Variable? A variable is a memory location that stores a value or character(s). How do I Write a Complete Algorithm? Follow the IPOS to program. Input - what are the items that the user has to enter into the computer? Process - what are the expressions that have to be evaluated? Output - display the end-results to the user Storage - ensure that the program is available for use at a later time. © Copyright 2011 by P.E.P. 3 CSC 155 Computer Science I Week 1 An Overview of Computers and Programming Languages Lecture Notes Student Name Consider this algebraic example: A circular trampoline measures 62.8 square feet in area. Given 3.14 , determine the circumference of the trampoline. What are the steps to solve this problem? First, knowing that the area of a circle is A r2 We divide the given area A by . A / r 2/ A / r 2 r 2 A / Next, take the square root of both sides. r ( A / ) Once the radius is known, I can compute the circumference C . C 2 r How do I write the above problem using a programming language? //Here is that math problem written in the C++ language. //preprocessing directives #include <iostream> #include <cmath> using namespace std; void main() { //First, knowing that the area of a circle is double A = 62.80, r = 0, C = 0; //compute the radius r r = sqrt(A / 3.1416); //compute the circumference C C = 2 * 3.1416 * r; //display the circumference cout << "the circumference is " << C << endl; } Here is the sample output. © Copyright 2011 by P.E.P. 4 CSC 155 Computer Science I Week 1 An Overview of Computers and Programming Languages Lecture Notes Student Name What Type Of Programming Applications Can We Create? (1) (2) (3) (4) (5) (6) Data Structures with functions ( searching and sorting algorithms ) Create RPG ( Role Playing Game ) game simulations. Examine a binary logarithm. Examine an infinite series ( sine or cosine ) . Process data through a file ( linear regression ) Data Encryption ( Cryptography - the Black Chamber ) http://www.simonsingh.net History of Computer Science Languages FORTRAN ( 1957 ) COBOL ( 1959 ) BASIC ( 1964 ) C ( 1969 ) C ++ ( 1987 ) Visual Basic ( 1991 ) Java ( 1993 ) C # ( 2001 ) The Future Science Business Data Processing Hobby, Non-Professionals AT & T AT & T Object - Oriented Visual Design Interface Web Applications ( True OOP language ) A Mixture of Java and C - Web Applications Natural Languages A Review of Structured Programming Textbook Chapter 0 An Introduction to Computers and Programming Languages. What is a PC System? http://www.old-computers.com © Copyright 2011 by P.E.P. 5 CSC 155 Computer Science I Week 1 An Overview of Computers and Programming Languages Lecture Notes Student Name Type of Languages ( Levels ) Machine ( lowest level ) Assembly Low - Level High - Level Natural Languages ( highest level ) Textbook Chapter 1 Basic Elements of C ++ Declaring Variables and Constants double Gross_Pay = 0.0; The above statement declares a variable named Gross_Pay that is initialized to 0 and is going to hold a real number with decimal points. int counter = 0; The above statement declares a variable named counter that is initialized to 0 and is going to hold a real number without decimal points. Data Types char bool double int float character Boolean Real Integer Real ( less precision ) Textbook Chapter 2 Input / Output What are the input and output requirements of a program? Here are the six steps to writing a good program. - Define the Problem - Develop an Algorithm - Code the Algorithm - Test the Code - Implement the Program - Maintain the Program © Copyright 2011 by P.E.P. 6 CSC 155 Computer Science I Week 1 An Overview of Computers and Programming Languages Lecture Notes Student Name Three Types of Program Control - Sequence ( in a step by step order ) - Selection ( making a decision ) - Repetition ( looping ) An example of sequence control: determining the total purchase price after a number of items have been selected for purchase Using Visual Studio 2010 MS Web Site Visual C++ Express Edition 2010 http://www.microsoft.com/express Review Questions (1) The language of a computer program is the same as the __________ . (a) (c) (2) logical design flowchart wisdom into data information into data input an assignment statement (b) (d) output input and output ! (b) @ (c) # (d) + (e) & Which is true about variables? (a) (b) (c) (d) (e) (6) wisdom into knowledge data into information In computer programming, the symbol to sum two numbers is __________ . (a) (5) (b) (d) A parallelogram in a flowchart represents __________ . (a) (c) (4) syntax philosophical orientation An information system will transform __________ . (a) (c) (3) (b) (d) The underscore is the only symbol that can be used in a variable name. The name must be on the keyword list. The name is created by the compiler. The name is generated by the Java design environment. The name must start with a capital letter. Which mathematical operation is performed first in an equation with no parentheses? (a) (c) Addition Exponentiation © Copyright 2011 by P.E.P. (b) (d) Division Integer division 7 CSC 155 Computer Science I Week 1 An Overview of Computers and Programming Languages Lecture Notes Student Name (7) Which is true about an assignment statement? (a) (b) (c) (d) (e) (8) Printing a document is a type of __________ . (a) (c) (9) assignment output (b) (d) input assignment and input Which data type uses double quotation marks? (a) (c) (10) They store user key strokes. They store user mouse clicks. They put the results of an operation in a variable. They display information at a prompt. They display strings in a message box. string decimal (b) (d) character integer Pseudocode is __________ . (a) (b) (c) (d) (e) data that have been encoded for security the incorrect results of a computer program a program that does not work the obscure language computer personnel use when speaking a description of an algorithm similar to a computer language Input, Process and Output - Programming Exercises Enter the correct answer(s) in the space(s) provided. (11) Identify the following flowchart symbol and describe its use. This is a parallelogram symbol that is used for both input and output statements. (12) Identify the following flowchart symbol and describe its use. This is a diamond symbol that is used for a decision statement. (13) In computer programming, a variable is a symbol or name that stands for a value. For example, in the expression 2 * x + y , x and y are variables. What are the variables in the following expression? p , r and t p + p * r * t / 100 (14) An orbiting satellite traveled 3,500 miles in 45 minutes. What variable names would you use to find the satellite’s speed in miles per hour? miles, minutes, milesPerHour © Copyright 2011 by P.E.P. 8 CSC 155 Computer Science I Week 1 An Overview of Computers and Programming Languages Lecture Notes Student Name (15) Complete the following chart by entering either Integer, Decimal or String as the data type which bests matches the given variable name. variable name interest_Earnings numberOfUnits employeeName volume_Cylinder DollarAmountInAccount (16) data type Decimal Integer String Decimal Decimal Name three things that can be done in the housekeeping section of a program. (1) declare programmer name(s), (2) declare variable names and (3) add comment statements. (17) A program that is free of syntax errors is free of logical errors. (a) True (b) False Removing syntax errors is independent of freeing a program of logic errors. (18) Logical errors are much easier to locate than syntax errors. (a) True (b) False Logic errors are often more difficult to locate compared to syntax errors. (19) Often the programmer does not design the output. (a) True (b) False Programs are generally designed around the output. (20) Although a flowchart ( as its name suggests ) depicts data flow very well, it is not easily modified once written. (a) True (b) False Sample Online Quiz (1) You have been assigned to write a program that finds the batting averages for members of a local baseball team. What should be your first step in the process of solving this problem? (a) (b) (c) (d) (2) Which step occurs first in the execution of a C ++ program? (a) (c) (3) Determine who will be using the program ( This is part of defining the problem in the Top - Down approach. ) Determine the program inputs Determine the program outputs Write and test valid pseudocode execution loading (b) (d) linking preprocessing Which of these is a legal identifier in C ++ ? (a) (c) PIE * 2 2_DAY © Copyright 2011 by P.E.P. (b) (d) gross Pay NUM_1 9 CSC 155 Computer Science I Week 1 An Overview of Computers and Programming Languages Lecture Notes Student Name (4) Suppose a , b and c are int variables and a = 5 and b = 6 . What is the value of a after this statement executes: a = (b++) + 3; (a) (c) (5) 5 10 (b) (d) 9 11 Suppose a, b, and c are int variables and a=5 and b=6. What is the value of a after this statement executes: a = (++b) + 3; (a) (c) (6) iostream io.h cmath stdlib.h object - oriented structured modular All of the above C ++ enables __________ programming. (a) (b) (c) (d) (9) 9 11 C ++ enables __________ programming. (a) (b) (c) (d) (8) (b) (d) To use the predefined identifiers cin and cout in your C ++ program, make sure to include the < __________ > header file. (a) (b) (c) (d) (7) 8 10 operative object - oriented structured structured and object-oriented The ___________ translates code written in a high - level language into machine language. (a) (b) (c) (d) assembler compiler preprocessor linker © Copyright 2011 by P.E.P. 10