COMP215L

PROBLEM SOLVING WITH C LAB

INSTRUCTOR: Tom Wheeler (Office in Room 208) 941-0430 x5211

twheeler@kc.devry.edu (DeVry e-mail address)

twheeler@tfs.net (HOME e-mail address)

http://www.kc.devry.edu/homepages/twheeler

 

CREDIT HOURS: 1.0

 

TEXT: None (Laboratory experiments are part of this syllabus

 

The work in this laboratory course reinforces the concepts covered in COMP215, Problem Solving with C. Each project teaches a new feature of the C/C++ language. It is strongly recommended that the student be concurrently enrolled in COMP215.

PROJECT DESCRIPTION WEEK # DUE

1 FAMILIARIZATION 2

2 TEMPERATURE CONVERSIONS 4

 

3 VOLTAGE DIVIDER CALCULATOR 6

4 WAVEFORM ANALYSIS 8

 

5 NUMBER SORT 10

6 ELECTRONIC COMPONENT DATABASE 12

 

7 GRAPHICS: WAVEFORM PLOTTING 14

 

LABORATORY REPORT CONTENTS

 

Every person will turn in a complete lab report for each experiment performed in COMP215L. The content must be as follows:

 

  1. Cover Page -- Must be on unlined white paper. Must be typed or computer-generated. Contains:
  2. YOUR NAME

    COMP215L

    LAB NUMBER AND TITLE

    TODAY'S DATE

    DATE DUE (WEEK #)

     

    FOR: PROFESSOR WHEELER

     

    OPERATIONAL SIGN OFF____

    FINAL SIGN OFF____

     

    "THIS IS THE ORIGINAL WORK OF (your name)"

    (YOUR SIGNATURE)

     

     

    HINT:

     

    Make sure to have a completed cover page when you start each lab. No sign-off can be given without a proper cover page.

     

    ABOUT SIGN-OFFS:

     

    A sign-off will be given only during the scheduled laboratory period. The sign-off verifies that your program works correctly. No credit is given to any report lacking a sign-off. You must present your program listing and demonstrate correct operation to obtain a sign-off. Your name must be at the top of all program listings.

     

  3. End-User Documentation -- This should be a complete description of how to operate your program from an end-user's point of view. More information on this topic is given in the section "End-User Documentation."
  4.  

  5. Sample Run -- This is a printout of a "typical" run of your program. In most cases, this is obtained by first running your program, then pressing the SHIFT-PRTSC keys on the IBM PC keyboard. Alternatively, you can force all video output to the printer by using the MS-DOS redirection character. For example, if your program is called MYPROG.EXE and you want all of its output to be sent to the printer, execute your program from the DOS command line by typing:

 

MYPROG > PRN

 

 

  1. Program Listing -- A printed listing of your program. Your name must be at the top of all program listings. The program will be properly documented and commented throughout. See "Program Documentation." Flowcharts are not required, but if you feel it necessary, include them.

 

TURNING IN WORK

 

Work may only be turned in directly to the instructor, or his appointed representative, during the laboratory period. Do not turn in papers to room 208.

 

 

GRADING

 

Each report in COMP215L is worth 100 points. 7 reports are required, therefore, 700 points are possible in this course. Letter grades will be assigned according to the following table:

 

 

Letter Grade Percentage % Quality of Work

A 90 - 100% Exemplary

B 80 - 89 % Above average

C 70 - 79 % Average; meets expectations

D 60 - 69 % Below expectations

F < 60 % Inadequate, failing

 

Laboratory Report Grading breakdown:

 

End-user documentation 40 points

Overall neatness of entire report 30 points

Accuracy and readability of listing 30 points

--------------

100 points total

 

 

End-user documentation will be graded based on clarity, grammar, completeness, and neatness.

 

The program listing is evaluated for both accuracy and adherence to certain stylistic conventions including (but not limited to):

 

 

Course Policies

 

I. Lab Partners: There are no lab partners allowed in COMP215L.

 

II. Handing Work in: Work should be given directly to the instructor or his authorized assistant. Under no circumstances should work be turned in to any other persons (including the office) without advance permission from the instructor.

 

III. Late Work: Late laboratory reports are not accepted in COMP215L. Reports are due during or before the end of the laboratory of the week number indicated on the schedule on page 1 of this document. The laboratory period ends at xx:50 UTC of the second hour of the assigned period. (UTC=Coordinated Universal Time, Standard World Time).

 

IV. Lab Success Hints: The successful student will have worked through the majority of the source code before entering lab. Laboratory time should be used to proper advantage; this is the main time that the instructor will be available to assist in troubleshooting / debugging, and it is the only time that sign-offs will be available. Please plan your activities accordingly.

 

V. Plagiarism: Copying the work of another, and claiming it to be your own is plagiarism. This includes (but is not limited to) copying others homework, copying from a lab manual or textbook, or collusion. The minimum penalty for cheating in any form is a grade of zero for the element involved; in some cases, failure of the course and/or expulsion from the Institute will also result. All cases of misconduct will be documented and forwarded to Student Services for disciplinary consideration. The DeVry Student Handbook contains complete information on this topic.

 

Please do not turn in any work that is not your own! If in doubt, ask the instructor. Here are some ways to avoid any problems:

 

 

MISCELLANEOUS INFORMATION

 

Emergency Procedures: There are plaques located in the lab discussing

emergency procedures. The instructor will remain in charge of your class

group in an emergency.

 

Food and Drink: Are not allowed in the laboratory at any time, even in closed containers. Violators will be expelled from the laboratory.

 

GOOD DATA PROCESSING PROCEDURES

 

Computers will be used extensively in this lab. The student can expect to spend many hours creating and updating C programs; loss of this data can be disastrous! The following tips will help to minimize the chance of losing a project:

 

 

 

 

 

 

 

 

 

 

 

END-USER DOCUMENTATION

 

End-user documentation is the set of information that enables a relatively uninformed second party to properly operate your program. There are several points which should be addressed, including:

 

  1. Purpose of the Program. This should be a short summary of what results a user can expect from running your program.
  2.  

  3. Using the Program. Should have several basic pieces of information, including but not limited to:

 

 

 

 

 

 

For reports in COMP215L, the first item need not be addressed, as all students will be working under the same computer platform. Most laboratory projects will yield documentation that is less than one page in length. Keep documentation simple and concise. Your documentation must "walk" the user through a session with the software, showing all on-screen prompts, user inputs, and program responses.

 

Actual applications programs tend to be involved efforts, and as such, documentation becomes a much larger (and much more important) task. When writing documentation, always think of the uninformed end-user.

 

End-User Documentation "Dos and Don'ts"

 

 

PROGRAM DOCUMENTATION

 

Program documentation is information that is directed at a technical person who may be required to maintain your code. Later, someone (possibly you!) will most likely have to make corrections or additions to your program. The quality of program documentation (and the basic structuring of your code) largely determines how easy (or difficult) this task will be.

 

Documentation is generally done in at two forms. For involved projects, the flowchart is an excellent method for capturing the train of events inside a program. The flowchart should give a conceptual, "bird's eye" view of what is happening. Flowcharts should avoid specific details such as "increment the R register" unless such detail is necessary to understanding the overall action of the program. A more suitable comment might be "Add $1.00 to account balance," since this directly states what the desired effect is. In other words, flowcharts are more concerned with what is happening rather than how the machine mechanically achieves it.

 

The second form of documentation is the program listing. The program listing is a detailed explanation of the mechanics behind the execution of a task. It should be appropriately and thoroughly commented. In "C" programs, blank lines should be inserted to separate parts of a task that are logically separate, and indentation should be used where appropriate. Consider the two pieces of code below:

 

// This poorly-styled code actually works!

int my_function(x,y)

int x,y;

{int alpha,z;alpha=0;

for(z=1;z<10;z++) {alpha=alpha+particle(x,y*y,z);y--;}

return(alpha);}

 

This code will compile and execute just fine, but it's difficult for humans to understand and maintain. The purpose of this code (and how it fits into the context of the whole program) is impossible to determine by mere inspection. It would be easier to understand if it were written like this:

 

//////////////////////////////////////////////////////////////////////////

// Function: int my_function(int x,int y)

//

// Inputs: integers x and y. x is the RMS mass of the particle and y

// is its current velocity in Kilometers/uS.

// Returns: an integer with an approximation of the decelaration of the

// particle in Kilometer/uS^2

//

// Errors: There are no error conditions possible for this function.

//

//////////////////////////////////////////////////////////////////////////

 

int my_function(int x,int y)

{

int alpha,z;

 

alpha=0; // initial acceleration is assumed to be zero.

 

/* Compute the approximate acceleration using BIG AL's iterative method.

Reference: CAR AND DRIVER magazine, July 1990, pp 34-35. */

 

for(z=1;z<10;z++)

{

alpha=alpha+particle(x,y*y,z);

}

 

return(alpha);

}

 

 

Note that every instruction in a program listing isn't necessarily commented. Machine instructions, in and of themselves, are generally self-evident because of the use of mnemonics. The documenting comments therefore serve to illuminate individual ideas or concepts that are important for understanding HOW the machine is accomplishing the task at hand.

 

Every function you define should have a HEADER comment. This important field describes what the function does, what inputs it uses, and what outputs it produces. It should be written as if you were explaining how to use the function to another programmer.

 

Appropriate placing of comments, program elements, and use of indentation all help to make source code more easily understood.

 

 

 

PROJECT DESCRIPTIONS

 

For a program to be accepted, it must meet the minimum specifications for each project. Extra functionality, as a function of your own creativity, is encouraged, as long as it does not detract from the original purpose of the project (or make it difficult to evaluate or analyze.)

 

In most cases, the inputs and outputs of the program will be specified. Your program should have the exact inputs and outputs that we specify, otherwise it becomes difficult for us to check your program's operation.

 

 

 

PROJECT 1: FAMILIARIZATION

 

This is an exercise to make sure you can use the editor and compiler. Below is a "C" program. Use the editor to place it into a file called MYFIRST.C (or MYFIRST.CPP), and then compile it into a working program.

 

P.S: (Possible Scuttlebutt): There may be some errors in this program. Please fix them before compiling!

 

*/ This is my first C program. It will print the

 

message "Hello, World" and then print the sum and

 

product of two and five. /*

 

 

 

 

#incude <stdio.h>

 

/* The STDIO.H header is usually part of every C

program. */

main()

{

int a,b;

 

a=5;

 

b==2

 

 

pantf("\nHello, World!\n\n);

 

printf("The sum of two and five is %d \n\n", a+b );

 

printf("The product of two and five is %d \n\n," a*b );

 

// End of program number 1

//

//

 

 

PROJECT 2: TEMPERATURE CONVERSIONS

 

This program will produce a conversion chart to the user's specification for the three major units of temperature measurement, Celsius, Kelvin, and Fahrenheit.

 

The program will begin by asking the user for the range of temperatures (starting and ending temperatures) in degrees Fahrenheit. It will then produce a neatly formatted table giving the Fahrenheit temperature and equivalent Celsius and Kelvin temperatures for each point in the list. The table must look like this:

 

Starting Temperature: 74 F Ending Temperature: 80 F

 

Degrees F Degrees C Degrees K

------------------------------------------

74 23.333 296.483

75 23.888 297.039

76 24.444 297.594

77 25.000 298.150

78 25.555 298.706

79 26.111 299.261

80 26.667 299.817

 

 

Formatted PRINTF statements will be used to force the decimal points to line up within the table, and three digits will be displayed to the right of the decimal points on the C and K columns. The F column will be computed and displayed as an INTEGER result with 1-degree F "steps" between values.

 

PROGRAM INPUTS: Starting and ending temperatures, degrees F

 

PROGRAM OUTPUT: Correctly formatted table as above.

 

IMPORTANT INFORMATION:

 

 

 

 

 

PROJECT 3: VOLTAGE DIVIDER CALCULATOR

 

This program will solve voltage divider circuits with two or more resistors. The program will run as follows:

 

  1. The user will be prompted for the source voltage, which will be assumed to be the total voltage across the divider circuit.
  2.  

  3. The user will be asked how many resistors are in the divider circuit.
  4.  

  5. The program will ask for the value of each resistor in the circuit.
  6.  

  7. The program will output a table giving a numeric designator (R1, R2, etc) for each resistor, its value, and its voltage drop.

 

A sample run might look like this:

 

Voltage Divider Solver - COMP215L

 

WHAT IS THE SOURCE VOLTAGE? 5

HOW MANY RESISTORS ARE THERE? 3

WHAT IS THE VALUE OF R1 IN OHMS? 1000

WHAT IS THE VALUE OF R2 IN OHMS? 1500

WHAT IS THE VALUE OF R3 IN OHMS? 2500

 

VOLTAGE DIVIDER RESULTS

 

RESISTOR VALUE (OHMS) VOLTAGE DROP

------------------------------------------

R1 1000.0 1.000 V

R2 1500.0 1.500 V

R3 2500.0 2.500 V

 

PROGRAM INPUTS: Number of resistors, source voltage, and resistor values.

 

PROGRAM OUTPUT: Correctly formatted table as above.

 

NOTES:

 

 

PROJECT 4: WAVEFORM ANALYSIS

 

This program will compute the values for a sine wave of specified peak value given starting and ending angles in degrees. The program will calculate the minimum, maximum, and average values. Optionally, the RMS value can also be displayed. The flow will look like this:

 

  1. The program will ask for the peak voltage Vp.
  2.  

  3. The program will ask for the starting and ending values in degrees.
  4.  

  5. The program will compute Vp sin(x) for each angle in the range, and store the result in a DOUBLE array. 1-Degree steps will be used.
  6.  

  7. The program will compute the minimum and maximum values, as well as the average value.
  8.  

  9. The output will be displayed in tabular form.

 

A sample run might look like this:

 

Sine Wave Analyzer - COMP215L

 

WHAT IS THE PEAK VOLTAGE? 100

STARTING ANGLE IN DEGREES? 0

ENDING ANGLE IN DEGREES? 180

 

MAXIMUM VALUE = 100 V, MINIMUM VALUE = 0 V, AVERAGE = 63.66 V

 

ANGLE (DEGREES) VpSIN(X)

-----------------------------

0 0.00

1 1.75

2 3.48

...

89 99.98

90 100.00

...

180 0.00

 

 

NOTE: To prevent the table from scrolling off the screen, devise a way of making it stop every 20 lines or so, prompting the user to continue.

 

PROGRAM INPUTS: Peak voltage, starting angle, and ending angle.

 

PROGRAM OUTPUT: Correctly formatted table as above.

 

(Continued on next page)

 

 

 

(Project 4: Continued)

 

NOTES:

 

 

 

 

 

 

 

 

 

 

 

 

 

PROJECT 5: NUMBER SORT

 

In this exercise, you will write a program that takes a list of 10 integers, and sorts them into low-high or high-low order (end-user choice). The program will then print the sorted list, and report the AVERAGE, MAXIMUM, and MINIMUM values encountered in the list.

 

You must use an INT array in this program. You must use three functions; one to INPUT the values into the array, one to SORT the array (in desired order), and a third to OUTPUT the sorted array. This is a requirement for sign-off. The SORT function you write must use a bubble-sort algorithm.

 

PROGRAM INPUT: The ten numbers to be sorted.

 

PROGRAM OUTPUT: The sorted list of elements, and the average, maximum, and minimum element values.

 

 

TIP: If you look closely at the output of your sort routine, you'll see an easy way of extracting the minimum and maximum values from the list.

 

 

PROJECT 6:ELECTRONIC COMPONENT DATABASE

 

A program is to be designed that will fulfill the function of a simple component database. Up to 100 entries should be allowed in the database. It is suggested that your program be menu-based. You will have to decide what options are in the menus.

 

For each entry in the database, store the following:

 

 

Your program must be capable of the following:

 

a) SEARCH for a component by its PART NUMBER.

b) BROWSE the list of information.

c) ADD new entries, up to a total of 100 entries.

d) EDIT an existing entry in the database.

 

PROGRAM INPUT: Menu commands and component information.

 

PROGRAM OUTPUT: Information as requested by issuing menu commands. Entire database records should be printed in response to each request in a clear, readable format.

 

TIPS:

 

 

Electronic Component Database

 

1) Search for a part

2) Browse database

3) Add a new part

4) Exit program

 

Choose?

 

 

 

PROJECT 7: GRAPHICS: WAVEFORM PLOTTING

 

This program is an extension of project 4. It does everything that project 4 does, except that it also gives the option of graphic output. The program will be based on a menu structure as follows:

 

WAVEFORM PLOTTING

 

1. ENTER WAVEFORM PARAMETERS

2. VIEW WAVEFORM NUMERIC DATA

3. VIEW WAVEFORM GRAPHIC PLOT

4. EXIT PROGRAM

 

Entering "1" at the menu will cause the program to ask for the peak value, starting and ending angles as in lab 4.

 

Entering "2" will cause the printing of a formatted table of data to the screen as in the output of lab 4.

 

Entering "3" will cause the computer to graph the function using Turbo C graphics. On screen, proper axes will be drawn, with numerical values placed on them for angle and voltage. The axes will be scaled according to the waveform parameters.

 

 

IT IS VERY IMPORTANT THAT THIS PROGRAM BE DEVELOPED IN MODULAR FORM. IT IS TOO COMPLEX TO WRITE AS ONE PIECE OF SPAGHETTI CODE!!!