CSC1142 SYLLABUS

SPRING 03

 
**LAST UPDATED 1/31/03**

WEEK 1
LECTURE: syllabus; input,process,output; 3GL vs machine lang.; control structures; prog. cycle
READING ASSIGNMENT:: pp. 1-65
.

WEEK 2)
LECTURE: declaring variables & constants
LAB: create CSC1142 folder; home page – copying to ms word; copy sample programs – build & execute
READING ASSIGNMENT:: pp. 65-129

WEEK 3(2/2/03)
LECTURE: built-in math functions; intro to value returning functions
LABLab 1
READING ASSIGNMENT:: pp. 134-151

WEEK 4 (2/9/03)
2/12 (Wed): no classes, President’s birthday
2/13 (Thurs): no classes, Lincoln’s birthday
LECTURE; value returning functions; formatting numeric output (p.176);
                    output to disk file(p.178);
LAB:  LAB 2
READING ASSIGNMENT:: pp 158-198

WEEK 5(2/16/03)
LECTURE:  value returning functions ;disk input/output; void functions
LAB: LAB 3 Do exercise #7 on page 222 of your text;
READING ASSIGNMENT:: pp.203-219; 226-239 

WEEK 6(2/23/03)
LECTURE:  parameter passing: by value; by reference; disk input/output
LAB: LAB 3 due; start lab 4 due next week.
READING ASSIGNMENT  pp 244-256

WEEK 7(3/2/03)
LECTURE: Mon: review for exam 1; Wed: Exam 1
LAB:
READING ASSIGNMENT:: pp.
   

WEEK 8 3/9/03))
LECTURE: file input/output; selection; repetition
LAB: lab 5
READING ASSIGNMENT:: pp. 265-282; 300-318; 340-357
 

WEEK 9 (3/16/03)
**SPRING VACATION**

 WEEK 10(3/23/03)
LECTURE:  Priming Read (p. 343); “switch” statement (p.315); sequential access data files;
                     ARRAYS;
                       .

LAB: lab 6
READING ASSIGNMENT: pp.448-467 (data files); pp. 492-518 (arrays)
 
 WEEK 11(3/30/03)
 LECTUREArrays; struct; quiz 1: study week 8 handouts
LAB:
READING ASSIGNMENT:: pp.

WEEK 12(4/6/03)
LECTURE:
LAB:
READING ASSIGNMENT:: pp.

WEEK 13(4/13/03)
LECTURE: homework assignment due Mon.: modify sort for early detection of sorted list.
      quiz2(Wed.): struct & array of struct; array sort
LABlab 6 & lab 7 due
READING ASSIGNMENT:: pp. 380-399 (Manipulating Characters & Strings)

WEEK 14(4/20/03)
LECTURE:
LAB: lab 8 due; start lab 9
READING ASSIGNMENT:: pp.

WEEK 15 (4/27/03)
LECTURE:
LAB: lab 9 due ; start lab 10
READING ASSIGNMENT:: pp.

WEEK 16 5/4/03)
LECTURE:
LAB:
READING ASSIGNMENT:: pp.

WEEK 17 (5/11/03))

Last Week of Classes
LECTURE:
LAB: LAB 10 DUE
READING ASSIGNMENT:: pp.  
 
WEEK 18 (5/18/03))
FINALS Week
5/21/03, 1pm - 3pm: LAB FINAL EXAM

 

 

return to top>
 
 
 
 

LAB ASSIGNMENTS

 

LAB 1:

General description:

Write a program that inputs 4 different integers and outputs the sum of the integers and the largest integer.

Directions:

1. Use a for loop to enter one integer at a time.

2. After the loop terminates output the sum of the integers and the largest integer.

3. Here is a partial sketch of the program:

 

            for (j=0;j<4;j++)

           {

             //code to accumulate the sum

            // code to determine the largest integer

           }  // end of for loop

           // output the sum

          // output the largest

LAB 2:
General description:
Input 3 different integers in random order and output them in ascending order.

Directions:
1. Input the the 3 numbers into 3 separate variables.
2. Rearrange them in ascending order, using an additional variable as a swap area..
3. Output the 3 numbers in ascending order.
4. Pseudocode:
            input n1,n2,n3
            if n1 > n2 then swap n1 and n2 (move number in n1 to n2 and number in n2 to n1).
            if n2 > n3 then swap n2 and n3.
            if n1 > n2 then swap n1 and n2.
            output n1,n2,n3.

LAB 3:
 Do exercise #7 on page 222 of your text;

LAB 4:
Same as lab2 with the following modifications:
1. Create 4 functions:
 GetData, Sort, Swap and Display.
2. The
GetData function will input the 3 integers via the keyboard.
3. The
Sort  function will perform the ordering of the integers.
4. The
Swap function will swap the integers.
5. The
main function will call the GetData function and pass by reference 3 integer
    parameters (
out only) that will be assigned values by the GetData function.
4. The
main function will call the Sort function and pass by reference (in/out) the 3
    integers.
5. The
Sort function will call the Swap function and pass by reference (in/out) the 2
    integers to be swapped.
6. After calling the
Sort function, the main function will call the Display function
     and
pass by value (in only) the three integers passed back by the Sort function.

 

LAB 5:
Same as lab 4 except the data will be input from a disk file instead of the interactive method via the keyboard.
Replace step 5 in lab 4 with:
5. The main function will contain an input loop that will read 3 records from a disk file and
    process each of them as usual; each record will contain a set of 3 different integers. Create
    the disk file (using C++’s editor) with the following data:
             12 24 22
             23 45 78
             87 65 21
Example of input loop:
.
#include<fstream>
.
.
ifstream fin(“lab5data.txt”);
const int numrecs=3;
int j,n1,n2,n3;
for (j=0;j<numrecs;j++)
{
  fin>>n1>>n2>>n3;
// process
}

LAB6

INPUT: disk file call it LAB6IN.TXT
(name)     (hours)     (rate)
ABLE       35         10.00
BAKER     50         12.50
CRANE     40         10.00
DOE        60         10.00

PROCESS:
1.Compute regular pay
2. Compute overtime pay
    a.) 41 – 50 hrs at 1.5 the rate of pay
    b.) over 50 hrs at 2 times the rate of pay

OUTPUT: disk file & screen; call disk file LAB6OUT.TXT

NAME     HRS      RATE           REG           OT            TOTAL

ABLE       35       10.00              350.00          0.00       350.00
BAKER     50      12.50             500.00        187.50       687.50
CRANE     40      10.00             400.00          0.00       400.00
DOE         60       10.00              400.00        350.00       750.00

 
 DIRECTIONS
1. Include a hierarchy chart depicting the various modules (functions).
2. Include an IPO CHART for each module, indicating what the function does and also the parameters: in only; in/out; out only..
3. Be sure to push down the details by dividing the program into meaningful functions.

LAB 7

Modify LAB 6 as follows:
    1. grand totals added to lab 6 (see below);
    2. use value-returning functions where possible;
    3. use STRUCT to define a line of data as a RECORD.

NAME     HRS      RATE           REG           OT            TOTAL

ABLE        35      10.00             350.00          0.00       350.00
BAKER      50      12.50             500.00       187.50       687.50
CRANE      40      10.00             400.00          0.00       400.00
DOE         60      10.00             400.00        350.00       750.00

GRAND TOTALS                     1650.00        537.50       2187.50
 
 LAB 8

Modify structArray.cpp: the loadFile function should be modified to detect a case where the array is not large enough to hold the records in the disk file.

LAB 9

GENERAL: You will write a program that counts the vote of an election and produces various statistics.

NOTE:

Candidate 1= ABLE
Candidate 2 = BAKER
Party 1 = REPUBLICAN
Party
2 = DEMOCRAT

 
INPUT: (call the file lab9in.txt)  Each record represents a single vote.
 (candidate)   (party)
       1                2
       2                1
       1                2
       1                1
       2                1
       2                2
       1                1
       1                1
       2                2
       2                2
       1                1
       2                1
       2                2

PROCESS:
- Use a 2X2 matrix to accumulate the vote as you read the records from the disk.
- The row of the matrix  will represent the candidate.
- The column of the matrix will represent the party.
- Use a one dimensional array to store the names of the candidates.
- Use a one dimensional array to store the names of the parties.
- Use a one dimensional array to accumulate the total votes cast by each party..

 

OUTPUT:
                          REPUBLICAN      DEMOCRAT     % OF REP.    % OF DEM
ABLE                           4                             2                         57                   33
BAKER                        3                             4                         43                   66
Total Rep Votes 7
Total Dem Votes 6

 
 DIRECTIONS
- Utilize the input data as row & collumn designations for the matrix.
- The matrix and the various one dimensional arrays should be designed to
   correspond
with each other.

LAB 10

GENERAL:

Generate a sales report with subtotals – control break logic.

INPUT:

(sales id) (amount)

S1                    500

S2                    350

S1                    225

S3                    100

S1                    600

S2                    290

S3                    450

 

OUTPUT:

SALES ID      AMOUNT

S1                                500

S1                                225

S1                                600

*TOTAL                    1325     

S2                                350

S2                                290

*TOTAL                      640

S3                                100

S3                                450

*TOTAL                      550

**GRAND TOT       2515

 

DIRECTIONS:

  1. Create a disk file with the data arranged in the same order as the input above.
  2. Declare an array of struct (salesId, amt), and load it with the data from the disk file.
  3. Pass the array (from main) to a sort function that will sort the records by salesId.
  4. Main will pass the sorted array to a function that will generate the output.

 

 

 

<return to top>
 

 
 
 

HANDOUTS

 

<return to top >

 

<return to top handouts>

 

 

 

<return to top handouts>

 

HANDOUT #5

(Illustrates Disk Text Files)

 
 

  1. /* ILLUSTRATES INPUT/OUTPUT OF (DISK) TEXT FILES:
  2.      INPUTS FROM A TEXT FILE AND OUTPUTS TO A TEXT FILE. */
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6. using namespace std;
  7.  
  8.  void main()
  9.  {
  10.  char data1[5];
  11.  int data2;
  12.  ifstream InFile;
  13.  ofstream OutFile;
  14.  // OPEN FILES
  15.  InFile.open("vc1in.txt");
  16.  OutFile.open("vc1out.txt");
  17.  //
  18.  // USE FOLLOWING AS MODEL INPUT LOOP
  19.  InFile >>data1>>data2; // priming read
  20.  // BEGIN INPUT LOOP
  21.  while (! InFile.eof())
  22.  {
  23.  // PROCESS DATA
  24.  cout<<data1<<"  "<<data2<<endl; // data1 is terminated by the 1st blank
  25.  OutFile <<data1<<"  "<<data2<<endl;
  26.  //
  27.  InFile >>data1>>data2; // main read
  28.  } // END INPUT LOOP
  29.  // CLOSE FILES
  30.  InFile.close();
  31.  OutFile.close();
  32. . //
  33.  cout <<"** end of program **" <<endl;
  34.  }

<return to top handouts>
 

HANDOUT #6

(Illustrates Modularity and Parameter Passing)

 
 

  1.  /* ILLUSTRATES MODULARITY AND PARAMATER PASSING;
  2.    COMPUTES GROSS PAY. */
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6. using namespace std;
  7. // GLOBALS
  8. const float rate=  (float) 10.55;
  9.  ifstream InFile;
  10.  ofstream OutFile;
  11. //
  12. // DECLARE FUNCTIONS
  13. void compute_pay(char name[5],float hours);
  14. void open_files(ifstream &infile,ofstream &outfile);
  15. void close_files(ifstream &infile,ofstream &outfile);
  16. void process_payroll();
  17. //
  18. void main() {
  19.  open_files(InFile,OutFile);
  20.  process_payroll();
  21.  close_files(InFile,OutFile);
  22.  cout <<"** end of payroll **" <<endl;
  23. }
  24. void compute_pay(char name[5],float hours) {
  25.  float gross_pay;
  26.  gross_pay=rate*hours;
  27.  cout <<name<<"  "<<hours <<"gross_pay= "<<gross_pay<<endl;
  28. }
  29. void open_files(ifstream &infile,ofstream &outfile) {
  30.  infile.open("vc1in.txt");
  31.  outfile.open("vc1out.txt");
  32. }
  33. void close_files(ifstream &infile,ofstream &outfile) {
  34.  infile.close();
  35.  outfile.close();
  36. }
  37. void process_payroll() {
  38.  char data1[5];
  39.  float data2;
  40.  // INPUT(priming read)
  41.  InFile >>data1>>data2;
  42.  // BEGIN INPUT LOOP
  43.  while (! InFile.eof())
  44.  {
  45.    // PROCESS
  46.       compute_pay(data1,data2);
  47.    // OUTPUT
  48.    OutFile <<data1<<"  "<<data2<<endl;
  49.    //INPUT (main read)
  50.    InFile >>data1>>data2;
  51.  } // END INPUT LOOP
  52. }

 

HANDOUT #7

(C++ OPERATORS)

RELATIONAL OPERATORS                                    LOGICAL OPERATORS
==      EQUALS
!=       NOT EQUAL                                          !            NOT
>        GREATER THAN                                     &&          AND
<        LESS THAN                                           ||           OR
>=      GREATER THAN OR EQUAL
<=      LESS THAN OR EQUAL

NOTE: Do not confuse the relational operator(==) with the assignment operator(=).
 
//SAMPLE8.CPP
// Illustrates  PARAMETER PASSING mixed with GLOBALS, resulting in a mix-up.
// The global variable "x" and the FORMAL parameter "a" refer to the SAME AREA OF MEMORY!!!!

#include <iostream.h>

// FUNCTION PROTOTYPES
void f1(int &);
//
int x;   // GLOBAL variable
void main()
{
 x=55;
 cout<<"MAIN: Passing x to f1 "<<"x= "<<x<<endl;
 f1(x);
 cout<<"MAIN: "<<"x= "<<x<<endl;

}

void f1(int &a)
{
 cout<<"f1:  "<<"a= "<<a<<endl;
 a=2*a;
 x=22222;
}
 

 // SAMPLE9.CPP
1. // IF/ELSE CASE INVOLVING A SINGLE VARIABLE
2. #include <iostream.h>

3. void main()
4. {
5. char shape;
6. cout<<"enter shape"<<endl;
7. cin>>shape;
8. if (shape=='t')
9. cout<<'t'<<endl;
10. if (shape=='r')
11. cout<<'r'<<endl;
12. if (shape=='c')
13. cout<<'c'<<endl;
14. // Difficlty determining BAD CODE using  IF construction above (see below for improvement))
15. //Using MULTI-WAY "IF" as alternative to above.
16. if (shape=='t')
17. cout<<"tm"<<endl;
18. else if (shape=='r')
19. cout<<"rm"<<endl;
20. else if (shape=='c')
21. cout<<"cm"<<endl;
22. else
23. cout<<"BAD CODEm"<<endl;
24. // Using SWITCH is a better method yet!
25. switch (shape){
26.   case 't':cout<<"ts"<<endl;break;
27.   case 'r':cout<<"rs"<<endl;break;
28.   case 'c':cout<<"cs"<<endl;break;
29.   default: cout<<"BAD CODEs"<<endl;break;
30. }  // END OF SWITCH
31. }
 
 
 
 
 
 
 
 

<return to top handouts>
 

 

1