CSI 147 - Module #01   
   
(Week One Material)

Dr Raj Gill, Computer Science Department

Home Page

Handouts

Syllabus

Modules

Topics: IPO and flowcharting
Intro to C (variables, constants, and reading & writing data)
(Also read the related material in your textbook - see syllabus for Chapter#)

Module 01 Objectives

1.  Specify Pre-requisites
2.  Review Syllabus
2.  Discuss difference between a variable and a constant
3.  Review IPO and Flow-charting
4.  Identify parts of a C program
5.  Identify Rules for Naming user-defined identifier/constants
6.  Discuss Built-in Data Types
7.  Discuss Program Style
 

College Core Competencies

Student Learning Course Outcomes

Criteria  for Outcome Assessment

   Critical Thinking and 
     Problem Solving

     Communication

1.   Analyzes given business,
      mathematical, and scientific
      problems for specifications in terms
      of input, output, and processing.

2.  Design a solutions to a given problem

For each given problem, the learner correctly

(i)       determines what is to be read in the program (input), what is to be printed (output), and how to convert input to output (processing).

(ii)     completes a flowchart or writes an algorithm

(iii)  designs test cases to figure out the output


Pre-requisites
    a.  CSI 115  or its equivalent programming experience
     b.   access to a computer system with C++ compiler
     c.    access to Internet
     d.   self-discipline to keep up with the schedule
     e.   course textbook(s)
 
Review Syllabus - pay attention to different topics discussed especially
  
- check the due dates for labs/projects
    - check the test dates and note that tests are to be taken in Testing Center
    - read the guidelines for turning in labs/projects; you are to turn in four file for each lab
              myLab.cpp   myLab.txt    MyLabOut.txt   MyLabFlowchart.doc
      See syllabus for explanation of each file
    - read about student responsibilities
    - Print the Handout on Criteria for Grading Labs
 
Using C++ Compiler
   - There are many C++ compilers.  It is NOT possible for the instructor to know intricacies of
      each compiler; so please take time to learn the compiler you plan to use for this course.
   -  Turbo C++ compiler is available for purchase for about $50 from College Book Store. 
       This is the compiler installed in College labs and is also made available to enrolled students
       online.  Online C++ compiler access is an extra service provided by the College and may
       not be always available.  So plan accordingly.
   -  There are many free C++ compilers on the web.  I have prepared a handout on one of the
       free compilers.  If you download it, print the optional handout mentioned below.
    -  If you prefer to use UNIX system (a minicomputer), ask me for a login ID and password.
       There are two optional handouts on how to use UNIX system for creating and
       executing C++ programs.  Try this route ONLY if you have used UNIX before and  you
       can handle it on your own.  See UNIX handouts mentioned below under the Assignment.
 
A word of caution about file names in some compiler environments
 
NOTE:  Some compilers such as some versions of Turbo C++ do not like disk file names longer than 8 characters before extension (.) and more than 3 characters for the extension.  Check your system or follow the above rule. 

For example, use file names such as        
            
sphere.cpp  or lab1data.txt or lab1out.txt or lab1Code.cpp
are good; but
             sphereProgram.cpp  OR   lab1datafile.txt
may not be.  Check your system.          

 

Given a problem, (a) determine input, processing, and output (IPO) statements and (b) draw flowchart

   Example#1: Enter regular price of an item; compute discount amount at 20% of regular price
                 and the item's discounted price.  Print discount amount and discounted price.

     (a)  IPO of the above problem:
            I --> Input 
                      
regular price of item
            P -->  Processing 
                     
discount amount = .20 * regular price  (20% of regular price)
                     discounted price = regular price -  discount amount 
           O -->  Output
                    
print discount amount and discounted price

      
(b) Flowchart symbols: (see Handout #00 for completed flowchart)
           Symbol for Start/Stop -->  oval                
           Symbol for Input/Output -->  parallelogram

            Symbol for Process (computations) -->  rectangle                            
             Symbol for decision -->  diamond    

             Symbol for a block of statement -->  rectangle with extra vertical line on
             each end
                               
             Symbol for flow of logic
--> an arrow     (up, down, left, and right)

     Example#2:   Do IPO and draw flowchart for the following problem

              Enter radius of a circle, compute and print its area.
                  (Print Handout #01 for the answer)
Identify parts of a C program 
    
- documentation section
     - preprocessor statement
            - #include
            - #define
     - variable declaration section
     - C statements for IPO and flowchart 

             (see Handout #02 for a complete C program)

NOTES:
     Every C program has at least one function: main ()-->   Example:    int main (void)

     use of preprocessor statements
            - #include
is used to include a library header file.   Example:    #include <stdio.h>
            - #define 
is used to declare constants.                  Example:    #define PI 3.14

    You must declare identifiers (variables names and constants) used in a C program
    Data types for Identifiers: int, float, char, short, long int, octal, hex, string of char
               
(See Table #2 below; more in Module 02)
 Rules for Naming user-defined identifier/constants

    - all names begin with an alpha character (Note: name could begin with an
                    underscore but should avoid it to prevent conflict with special system names)

    - after the first letter, any combination of letters, digits, and
       underscore can follow
    - no embedded spaces allowed
    - no keywords allowed (see the Appendix on C keywords)
    - Names are case sensitive;
sum, SUM, and Sum occupy different memory locations
    
- In UNIX system, first 31 characters are significant; check your own system
    
- do not split variables over two lines

        Note: same rules apply for variables, constants, function names, and
                 struct names (you will learn about struct later in semester) 


        Some examples of valid and invalid names are shown in Table 1.
                                                               Table #1

Good Variable names Invalid Variable Names
test3_score
column_no32
can_have_long_name12
MyTotalScoreOnTests
my_total_score_on_tests
total amount due (has spaces)
3test_score (begins with a digit)
column_#32 (has #; only letters,
      digits, and underscore allowed)

return (keyword not allowed)

Besides user-defined identifiers (often referred to as variables), there are
standard identifiers (such as scanf and printf) names supplied in stdio.h file

Constant identifiers are defined using #define preprocessor directive.  For example
              #define PI 3.14159            //note there is no equal sign and no semicolon
It can also be declared as
              const float PI = 3.14159;     //Note equal sign and semicolon

Use UPPER CASE for naming constants and lower case for variables.
Use underscores to separate different words in variables and constatnts.

All languages contain reserved words (or key words) which can not be used as variables. 
Some of the C key words are: 
              int, double, for, while, switch, if, else, return...
All C reserved words are listed in an Appendix in your text.  
For each lab to be turned in for grading, prepare IPO and design solution to a Problem (do flowchart)
(see
Handout #01)
   
- Input/Process/Output (IPO) analysis of programming problem
    - draw flowchart
    - Remember --> oval for start/stop; parallelogram for input/output; rectangle for
      process/computations; diamond for decision; module symbol for
      block of code or a function; connecting arrows
Built-in Data Type and Conversion Specification Characters (or place holders) for Input/Output
%d is used for printing or reading an int value; others are listed below.  They hold a 
place where the value will be printed and convert data into displayable form; hence, they are referred 
to as conversion specification.

                                                           
Table #2
Data Type int short int long int float char octal hex
control char %d or %i %hd %ld %f %c %o %x
  sizeof 2 or 4 2 bytes 4 bytes 4 bytes 1 byte    

        Note: (i)  Typical sizes for various types of data are listed in the
                       table above.  However, these could be system
                       dependent (except for char data type
                       which is always stored in one byte)
                 (ii)  String of characters is read or printed using %s
                 (iii) If a variable is declared as double, it is read using %lf
                       but it is printed with %f
                 (iv) An int data is usually stored in 2 bytes on PCs and it ranges from -32768 to 32767;
                       int data outside this range should be declared as long int if using PC,
                       otherwise, you will get junk answer
                 (v)  Since an int is stored in 4 bytes on mainframes and minicomputers, int can store
                       a large integer number on these machines.  There is no need to use long int
                       on such machines.

Contact Professor and Professor Office Hours
Go to Home Page and click on Professor link.
 
Program Style
     
Please see Module 2 for detailed discussion of the program style you should use
      for this class.  A section on program style is included in modules where a new 
      construct or new concept is discussed.
 
Your Turn:
  
Questions: Use notes above and/or your text to answer the following questions
   1.  Use #define to declare STATE_TAX  at 5% (0.05)
   2.  Are these valid variable names? Why/Why not?    
$balance_due      return
  
3.  What is name of the function every C program must have?
   4.  The variables,
score, area,  and account_balance are declared below.
              
int  score;
               long int area;
               float account_balance;
       Give Conversion Specification Characters (or place holders) to read and print
       values stored in them.
   5.  Write a C statement to include math.h library header file
   6.  Give the IPO and draw a flowchart for the following problem:
              Enter two numbers, compute and print their sum and product.
 
Assignment:  Print the handouts listed below, read them and work on Lab#1
   
  1.         Handout #00 -- flowchart for discounted price
  2.         Handout #01 -- circle flowchart (designing a solution)
  2.         Handout #02 -- circle program (implementing solution)
  3.         Handout #03 -- Using Borland C++ Builder 5  
  4.         Handout #04 -- creating program file using vi (optional*)
  5.         Handout #05 -- printing output using script    (optional*)
  6.         Print Lab#1 Handout and work on it 
            Please Note:
Follow the style in handouts listed above to do 
                              all your Labs


*  Handouts labeled optional are for those students who want to
   use UNIX operating system environment.
Assess Yourself 
    
After completing the above module, click on the red text below to
     complete module assessment.  This activity counts towards your class
     participation.     
Click Here to Get to Feedback Form                            
-------------------------------------------------------------------------------------------------------
Answers to Questions Above

       1.   #define STATE_TAX  0.05
       2.   Both are invalid;
$balance_due begins with '$' which is not allowed;  return is
             a keyword and therefore is not a valid variable name.
       3.   main()
       4.   %d for
score;  %ld (% ell dee) for area;  %f for account_balance;
       5.   #include <math.h>
       6.   I -->  Input number1 and number2
            P -->  sum = number1 + number2
                     product = number1 * number2
            O -->  print sum and product
 
 
        This page has been visited Hit Counter times
 

                    Copyright© 2004 --  Raj Gill