User Tools

Site Tools


Sidebar

projects

pct0 (bonus; due 20230823)
wcp1 (due 20230823)
abc0 (due 20230830)
pct1 (bonus; due 20230830)
pct2 (due 20230830)
wcp2 (due 20230830)
gtf0 (due 20230906)
pct3 (bonus; due 20230906)
wcp3 (due 20230906)
dtr0 (due 20230913)
pct4 (due 20230913)
wcp4 (due 20230913)
pct5 (bonus; due 20230920)
stl0 (due 20230920)
wcp5 (due 20230920)
gfo0 (due 20230927)
pct6 (due 20230927)
stl1 (due 20230927)
wcp6 (due 20230927)
pct7 (bonus; due 20231004)
ptb0 (due 20231004)
wcp7 (due 20231004)
bwp1 (bonus; due 20231018)
pct8 (due 20231018)
ptb1 (due 20231018)
wcp8 (due 20231018)
pct9 (bonus; due 20231025)
ptb2 (due 20231025)
wcp9 (due 20231025)
eap0 (due 20231101)
gfo1 (due 20231101)
pctA (due 20231101)
wcpA (due 20231101)
pctB (bonus; due 20231108)
wcpB (due 20231108)
eap1 (due 20231109)
eap2 (due 20231115)
pctC (due 20231115)
wcpC (due 20231115)
bwp2 (bonus; due 20231129)
pctD (bonus; due 20231129)
wcpD (bonus; due 20231129)
gfo2 (due 20231206)
pctE (bonus; due 20231206)
wcpE (bonus; due 20231206)
EoCE (due 20231214)
haas:fall2023:c4eng:projects:mtf0

Corning Community College

ENGR1050 C for Engineers

Project: LOOPS - MATH TABLE FUN (mtf0)

Objective

To start incorporating loops into our problem-solving repertoire, aiding us in displaying information related to various math tables.

Reading

In “The C Book”, please read through Chapter 4.

Background

Although we have encountered the use of loops in various class examples programs driving electronics on the raspberry pi, being able to utilize a loop to alter control flow in your programs is a very important skill. It starts to usher in dramatically increased levels of optimization in our solutions, saving us from needlessly writing redundant code that is largely the same, but only changes in some predictable way.

Types of Loops in C

There are 3 types of loops available to us in C, all numerical/conditional in nature:

  • for loop - typically used when we have a known starting and stopping place, and a clear means of progressing from start to end (top-driven, runs 0 or more times)
  • while loop - used when we know when we'd like to stop, but do not necessarily know where we will start. Much more conditional in application (top-driven, runs 0 or more times)
  • do-while loop - like the while, only we perform the test at the very bottom (bottom-driven, runs 1 or more times)

Program

It is your task to write the program that will use loops and other programming concepts learned this far to automate the display rows of various mathematical tables (addition or multiplication, as indicated by the user). This information is potentially of value to some of your letter division efforts in the pctX projects.

Your program should:

  • have valid, descriptive variable names of length no shorter than 4 symbols
    • I will make an exception for the use of 'row'
  • prompt the user for the operation ('+' for addition, '*' for multiplication)
    • properly store this in a variable of type (signed) char
    • check for a literal '+' or '*' symbol to determine operation to perform
      • if invalid input, display an error and exit with a non-zero value
  • prompt for the row (0-9)
    • properly store this in a variable of type unsigned short int
  • prompt for the starting column (0-9)
    • properly store this in a variable of type unsigned short int
  • prompt for the ending column (0-9)
    • properly store this in a variable of type unsigned short int
  • check to make sure starting column is less than or equal to ending column
    • if not, display an error (to STDERR) and exit with non-zero status code
  • display the row of the table, performing the indicated operation
    • display each numerical value in organized, consistent fashion, assuming two-digit numbers
  • using a single return statement at the conclusion of the code, return a 0 indicating successful operation

Execution

Sample run using multiplication

lab46:~/src/c4eng/mtf0$ ./mtf0
Which operation ('+' or '*'): *
Row (0-9): 4
Starting Column (0-9): 1
Ending Column (0-9): 5
 4:  4  8 12 16 20
lab46:~/src/c4eng/mtf0$ 

The execution of the program is short and simple- obtain the input, do the processing, produce the output, and then terminate.

Sample run using addition

lab46:~/src/c4eng/mtf0$ ./mtf0
Which operation ('+' or '*'): +
Row (0-9): 5
Starting Column (0-9): 2
Ending Column (0-9): 7
 5:  7  8  9 10 11 12
lab46:~/src/c4eng/mtf0$ 

Sample run with invalid operation given

lab46:~/src/c4eng/mtf0$ ./mtf0
Which operation ('+' or '*'): x
ERROR: Must specify either '+' or '*'.
lab46:~/src/c4eng/mtf0$ 

Sample run with invalid column configuration

lab46:~/src/c4eng/mtf0$ ./mtf0
Which operation ('+' or '*'): +
Row (0-9): 5
Starting Column (0-9): 7
Ending Column (0-9): 2
ERROR: Starting column is greater than ending column
lab46:~/src/c4eng/mtf0$ 

Submission

To successfully complete this project, the following criteria must be met:

  • Code must compile cleanly (no warnings or errors)
  • Output must be correct, and match the form given in the sample output above.
  • Code must be nicely and consistently indented
  • Code must be well commented
  • Do NOT double space your code. Group like statements together.
  • Output Formatting (including spacing) of program must conform to the provided output (see above).
  • Track/version the source code in a repository
  • Submit a copy of your source code to me using the submit tool.

To submit this program to me using the submit tool, run the following command at your lab46 prompt:

$ submit c4eng mtf0 mtf0.c
Submitting c4eng project "mtf0":
    -> mtf0.c(OK)

SUCCESSFULLY SUBMITTED

You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.

What I'll be looking for:

78:mtf0:final tally of results (78/78)
*:mtf0:proper error checking and status reporting performed [13/13]
*:mtf0:correct variable types and name lengths used [13/13]
*:mtf0:proper output formatting per specifications [13/13]
*:mtf0:runtime tests of submitted program succeed [13/13]
*:mtf0:no negative compiler messages for program [13/13]
*:mtf0:code is pushed to lab46 repository [13/13]

Additionally:

  • Solutions not abiding by spirit of project will be subject to a 25% overall deduction
  • Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction
  • Solutions not utilizing indentation to promote scope and clarity will be subject to a 25% overall deduction
  • Solutions not organized and easy to read are subject to a 25% overall deduction
haas/fall2023/c4eng/projects/mtf0.txt · Last modified: 2019/09/30 11:57 by 127.0.0.1