CSc 3320
Homework #4
DUE DATE: Wednesday, March 9, 2011
Objectives
1. Learning about C programming language: conditional statement, function, parameter passing, input and output, loop and other features.
2. Writing a C program with an input menu.
3. Learn how to compile and run a C code in Unix environment.
Introduction
Your assignment is given below. To solve it, write a C program that reads the necessary information to compute and output the indicated values, as efficiently as possible. First, design your program by specifying its behavior, identifying the objects and operations it needs to solve the problem, and then organizing the objects and operations into an algorithm. Then code your design as a C program using stepwise translation. Finally, test your program thoroughly.
Project
1. Write a C program which outputs a multiplication table, an addition table, or a power table. The script should be menu-based with the following options:
- (M) Multiplication Table
- (A) Addition Table
- (P) Power Table
- (Q) Quit
Also input the size S of the table. Each multiplication or addition table should contain S rows and S columns for numbers from 1 to S. The power table should also have S rows and S columns. For example, the second row of the power table would contain the values of 21, 22, 23, … 2S, and the last row would contain the values of 101, 102, 103, … 10S. The details of the three tables will be explained in class.
2. INPUT: Your program will need to know which table is to be produced. You may create a menu similar to the one discussed in class to make a choice. Each time, your input will be “M”, “A”, “P”, or “Q” until the program quits. Other inputs are illegal, and your program should print out an error message. You need also input the size of the table generated right after your menu selection.
3. OUTPUT: Echo a welcome message to the screen and print the menu on your screen. Based user’s choice, each time your program outputs a multiplication table, an addition table, or a power table. Your program will continue to execute until a “Q” is received in your input menu.
4. Be sure to include the header information as comments at the top of your source file.
5. As you are aware certain types of assistance are inappropriate in this class. Read the collaboration policy given to you at the beginning of the semester, if you have any questions.
6. Follow program standards as presented in class and in your book. Pay special attention to comments, identifier style, and consistent 3-space indentation. You should indent your code as you normally would. Use comments to make your program easy to read.
7. Use script assign4.log to record all things you type and the responses from the system. "assign4.log” is just the name of the file it creates. After finishing the recording, type CTRL-D to exit from your script session.
Special Requirements:
1. Use a different function to generate a different table. In other words, you need to have three functions for three different tables.
2. Also the size of the table should be passed from the main program to the function as a parameter.
3. Use both for loops and while loops in your code.
4. Define at least one symbolic constant. For example, TABLELIMIT.