User Tools

Site Tools


Sidebar

projects

wcp1 (due 20240828)
wcp2 (due 20240904)
pct0 (bonus; due 20240905)
pct1 (bonus; due 20240905)
pct2 (due 20240905)
abc0 (due 20240906)
gtf0 (due 20240911)
pct3 (bonus; due 20240911)
wcp3 (due 20240911)
dtr0 (due 20240918)
pct4 (due 20240918)
wcp4 (due 20240918)
mmf0 (due 20240926)
pct5 (bonus; due 20240926)
wcp5 (due 20240926)
cnv0 (due 20241002)
gfo0 (due 20241002)
pct6 (due 20241002)
wcp6 (due 20241002)
fwg0 (due 20241009)
pct7 (bonus; due 20241009)
wcp7 (due 20241009)
bwp1 (bonus; due 20241016)
cnv1 (due 20241016)
pct8 (due 20241016)
wcp8 (due 20241016)
fwg1 (due 20241023)
pct9 (bonus; due 20241023)
wcp9 (due 20241023)
fwg2 (due 20241030)
gfo1 (due 20241030)
pctA (due 20241030)
wcpA (due 20241030)
fwg3 (due 20241106)
pctB (bonus; due 20241106)
wcpB (due 20241106)
oop0 (due 20241113)
pctC (due 20241113)
wcpC (due 20241113)
pctD (bonus; due 20241120)
wcpD (bonus; due 20241120)
bwp2 (bonus; due 20241204)
gfo2 (due 20241204)
pctE (bonus; due 20241204)
wcpE (bonus; due 20241204)
EoCE (due 20241216)
haas:fall2024:cprog:projects:mmf0

Corning Community College

CSCS1320 C/C++ Programming

PROJECT: Mental Math Fun (MMF0)

OBJECTIVE

To explore relational decision making, as applied to a mental math process.

GRABIT

To assist with consistency across all implementations, data files for use with this project are available on lab46 via the grabit tool. Be sure to obtain it and ensure your implementation properly works with the provided data.

lab46:~/src/SEMESTER/DESIG$ grabit DESIG PROJECT

Please study any provided code, comments, or supporting documents, and look up, experiment, and ask questions on aspects that you do not understand.

EDIT

You will want to go here to edit and fill in the various sections of the document:

MMF0

In this project we are to determine, given a year as input, which day of the week the January 1st of that year falls on. We can determine this with an algorithm known as Zeller's congruence. Once we have compiled our project, we will be able to test different cases with the mmf0verify file.

Process

Input value as short int (all four digits)

mmf0verify uses stdin to write the year

  • fscanf can be used to read from stdin
  • The following line uses fscanf to read the stdin file, and assign the result to a variable named year
fscanf (stdin, “%hu\n”, &year);

The ampersand above is necessary to assign the inputted value to our variable. The ampersand tells the fscanf function where our variable is stored in memory, so that we may access and modify the value based on the input we receive from the verify script.

Obtain the last two digits of this input value

To obtain the last 2 digits of our inputted year, we can take our year and mod (%) it by 100. Because we are using Zeller's congruence, we must subtract 1 from the year beforehand since we're dealing with January, which is considered a part of the previous year.

Quarter the value
Add quartered value back to two digit year
Subtract best fitting multiple of seven

To subtract the best fitting multiple of seven the % operator can be used

  • Do note that % is the remainder operator and not a modulo operator
    • Modulo and remainder are primarily the same but they handle negative numbers differently
If it is a leap year subtract 1 more

However, if we are using Zeller's congruence this is an unnecessary step as this is handled implicitly by Christian Zeller's algorithm. This is why we January is considered a part of the previous year and is labeled as the thirteenth month rather than the first month.

Look up day in table
Day Value
Monday 1
Day Value
Tuesday 2
Day Value
Wednesday 3
Day Value
Thursday 4
Day Value
Friday 5
Day Value
Saturday 6
Day Value
Sunday 7
Day Value
Sunday 0
Edge case: leap years

Subtracting 1 because it is a leap year may result in a value either less than the variables range or outside of the expected range of outputs

An underflow can be remedied in many ways.

  • Adding 7 to the number when it is outside of the expected range
  • When the result would be outside of the expected add 6 instead of subtracting 1
  • etc

SELECTION

if statements

If statements allow code to be run conditionally, controlling the flow of code

An if statement has two parts; A boolean condition and a some block of code.

signed int a = 5;
signed int b = 6;
if(a == 5) {
fprintf(stdout, "The value of a is 5\n");
b = b*2;
}

if(b != 6) fprintf(stdout, "The value of b is not 6\n");
fprintf(stdout, "The value of b is %d\n", b);

This code uses if statements to control the flow of code.

  • The first if statement's boolean condition is a == 5, which evaluates to true.
  • Because it evaluates to true the block of code after it is ran. A block of code is surrounded by { }.
  • The second if statement's boolean condition is b != 6, which evaluates to true.
  • Because it evaluated to true the block of code after it is ran; However, the code after it has no { }, thus the only code that is controlled by the if statement is fprintf function directly after it
  • The final fprintf in this code will run unconditionally because it is not within a block of code that is controlled by an if statement
else if

Else if is an extension of an if statement. An else if statement must come directly after an if statement. It functions identical to an if statement, but is only ran if the prior if statement results in false.

int myVariable = 7;
if(myVariable == 7){
fprintf(stdout, "The value of myVariable is 7\n");
} else if(myVariable >= 7){
fprintf(stdout, "The value of myVariable is greater than 7\n");
}

The else if statement is used to further control the flow of code, while also reducing the amount of code.

Because else if is only ran if the prior if statement is false it completes the same task as if(myVariable != 7 && myVariable >= 7)

else

The else function is similar to the else if function in that it is only ran when the prior if statement results in false.

The else function however doesn't contain an if statement and will always run the following block of code.

int myVariable = 7;
if(myVariable == 7){
fprintf(stdout, "The value of myVariable is 7\n");
} else{
fprintf(stdout, "The value of myVariable is not 7\n");
}

The line The Value of myVariable is not 7 will always print unless myVariable == 7 results to true

The else function allows simple construction of an if than else statement.

RELATIONAL OPERATORS
Operator Description
== is equal to
!= is not equal to
< greater than
> less than
<= less than or equal to
>= greater than or equal to

VERIFY RESULTS

To verify your results, ./mmf0verify

Remember to only use stdout to print the days of the week [EX: fprintf(stdout, “Monday\n”)]. If stdout is used for anything other than the days of the week, the mmf0verify will say you have a mismatch for every year, even if you get the correct day when you run your compiled code. If you want to print something other than the days of the week, use stderr.

 

SUBMISSION

To be successful in this project, the following criteria (or their equivalent) must be met:

  • Project must be submit on time, by the deadline.
    • Late submissions will lose 33% credit per day, with the submission window closing on the 3rd day following the deadline.
  • All code must compile cleanly (no warnings or errors)
    • Compile with the -Wall and --std=gnu18 compiler flags
    • all requested functionality must conform to stated requirements (either on this document or in a comment banner in source code files themselves).
  • Executed programs must display in a manner similar to provided output
    • output formatted, where applicable, must match that of project requirements
  • Processing must be correct based on input given and output requested
  • Output, if applicable, must be correct based on values input
  • Code must be nicely and consistently indented
  • Code must be consistently written, to strive for readability from having a consistent style throughout
  • Code must be commented
    • Any “to be implemented” comments MUST be removed
      • these “to be implemented” comments, if still present at evaluation time, will result in points being deducted.
      • Sufficient comments explaining the point of provided logic MUST be present
  • No global variables (without instructor approval), no goto statements, no calling of main()!
  • Track/version the source code in your lab46 semester repository
  • Submit a copy of your source code to me using the submit tool (make submit on lab46 will do this) by the deadline.

Submit Tool Usage

Let's say you have completed work on the project, and are ready to submit, you would do the following:

lab46:~/src/SEMESTER/DESIG/PROJECT$ make submit

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.

RUBRIC

I'll be evaluating the project based on the following criteria:

65:mmf0:final tally of results (65/65)
*:mmf0:used grabit for project by Sunday prior to duedate [13/13]
*:mmf0:clean compile, no compiler messages [13/13]
*:mmf0:program performs mental math process [13/13]
*:mmf0:program output conforms to specifications [13/13]
*:mmf0:code tracked in lab46 semester repo [13/13]

Pertaining to the collaborative authoring of project documentation

  • each class member is to participate in the contribution of relevant information and formatting of the documentation
    • minimal member contributions consist of:
      • near the class average edits (a value of at least four productive edits)
      • near the average class content change average (a value of at least 256 bytes (absolute value of data content change))
      • near the class total content contribution average (a value of at least 1kiB)
      • no zero-sum commits: no adding in one commit then later removing in its entirety for the sake of satisfying edit requirements
    • adding and formatting data in an organized fashion, aiming to create an informative and readable document that anyone in the class can reference
    • content contributions will be factored into a documentation coefficient, a value multiplied against your actual project submission to influence the end result:
      • no contributions, co-efficient is 0.50
      • less than minimum contributions is 0.75
      • met minimum contribution threshold is 1.00

Additionally

  • Solutions not abiding by spirit of project will be subject to a 50% 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 or otherwise maintaining consistency in code style and presentation will be subject to a 25% overall deduction
  • Solutions not organized and easy to read (assume a terminal at least 90 characters wide, 40 characters tall) are subject to a 25% overall deduction
haas/fall2024/cprog/projects/mmf0.txt · Last modified: 2024/09/02 15:02 by 127.0.0.1