CP264 - A1 help

General

  • Start early, make progress step by step, submit early, don’t wait till last minutes.
  • In C programming, try to make it simple, clean, and robust. Test, test and test to make sure it meets specifications.
  • Follow program style for readability. Add progrm signature at begining, write documentation for each function.
  • Design and implement you own program. Type rather than copy lines and blocks. Program templates given in the help are examples of simple design of program solution structures. You are allowed to these program templates as long as you understand what they do.
  • Work individually, get help from course materials, instructors, and AIs when encounter difficulties. Avoid coping code from Internet or generated by AI. When using AI enabled IDE like VS Code, you are responsable for the code you derived from IDE’s suggestions or generated. That means you can re-write your code without any help.
  • You can do assignments on Windows, Linux, or Mac OS. However, markers only test and mark your assignment submssions on Windows machines.

General marking rules

  • All submissions will be checked according submission specs, compiled and tested by markers’ marking test driver and test cases.
  • A submitted solution may get 0 mark if it does not follow the question specifications (specs), or failed marking compiling, or failed all marking tests. It’s not likely that two people write the same code, so if two submissions contain the same code, both will get 0 mark if found.
  • Partial marks may be token off if submission package does not meet the submission requirements: no signature in program (-1), package contains extra folders and files (-1).


Add program signature like the following to your source code program files. This signature states that the program is your work.

/*
--------------------------------------------------
Project: a1q1
File:    mycase.h
Author:  your name
Version: YYYY-MM-DD
--------------------------------------------------
*/

Write your source code file mychar.h and mychar.c like the following.

mychar.h

mychar.c

Hint:

  1. For a particular type, say small English letter, use condition expression(c >= 'a' && c <= 'z') to check if c is a small English letter.
  2. For digit character c, use int x = c - '0'; to get the digit number and store in x.

testing

  • read mycase_ptest.c to see what it does.
  • Open cmd console, cd to the a1 folder, type the following command to compile.
gcc mychar.c mychar_ptest.c -o mychar
  • Run the public Test
mychar
  • Run public test in interactive mode using command like the following.
mychar 1
  • Read mychar_ptest.c to see to see how to get the number of command arguments, how to read a char value from keyboard, and how to use while loop to for next input, and how to quit.
  • Also read to see how to do the formatted output.


powersum.h

powersum.c

Hint:

  1. Use for loop to compute the bn, set p=1, for i from 1 to n, check if p*b is overflow, namely let temp = p*b if temp/b != p then overflow happens; otherwise set p = p*b.
  2. Use for loop to compute the bn, set p=1, for i from 1 to n, check if p*b is overflow, namely let temp = p*b if temp/b != p then overflow happens; otherwise set p = p*b. sum + bn is overflow if sum + bn < sum.

testing

  • read powersum_ptest.c to see what it does.
  • Open cmd console, cd to the a1 folder, type the following command to compile.
gcc powersum.c powersum_ptest.c -o powersum
powersum


For the monthly_payment(…) function, you can use expression:

principal * r * pow(1 + r, n) / (pow(1 + r, n) - 1)

to calculate the monthly payment, where principle is the principle amount, r = annual_rate/100/12 is montly rate, and n = years*12 is the number monthos.

pow(x, y) is the power function from math.h for computing xy. In order use the pow() function, you need to include the math.h in mymortgage.c file.

  • Compile
gcc mymortgage.c mymortgage_ptest.c -o mymortgage
  • Run the public test
mymortgage
  • Use command line argument to calculate a particular n!, e.g. 10!
mymortgage 1000,5.0,10
  • Read mymortgage_ptest.c to see to see how to get a formatted input from commmand line argument.

Creating submission package by command line operation

Open a cmd console or terminal, cd to the a1 directory. On Windows machine, use the following command.

7z a -tzip a1.zip  mychar.h mychar.c powersum.h powersum.c mymortgage.h mymortgage.c 

On Mac machine, use the following command.

zip a1.zip  mychar.h mychar.c powersum.h powersum.c mymortgage.h mymortgage.c 

Submission package test

Make sure that all file names are exactly as specified. You can try the following batch test to assure all your programs work properly (On Windows machines).

  1. Download this ptest.zip to test your submission.
  2. Unzip ptest.zip to a folder, say ptest.
  3. Copy your submission zip file to the ptest folder
  4. Click to run the test.bat
  5. Check the test_report.txt to see the comparison report of the output test_result.txt file and the provided solution test_solution.txt file. If they are same, then your programs will likely pass marker’s marking tests.
  6. Check q?c.txt to see compiling error message if it fails to create q?.exe
  7. Click clean.bat to clean up the generated files.