es26 - mp01 - wilmarc

3
ES 26 – Introduction to Programming First Machine Problem I. Project Title: Arithmetic Tutorial II. Objectives 1. To learn the diffe rent fa cets of creatin g a C pr ogram. 2. To learn ho w to wri te structu red an d mod ular C progr ams. III. Program Specifications The goal of this project is for the student(s) to write a program that will serve as a tutorial for people starting to learn basic arithmetic. The program will present the user a series of arithmetic problems involving two numbers and one of the four basic arithmetic operations (addition, subtraction, mul tiplication and div isi on) . The user tri es to answe r eac h proble m and ga rne rs “points” for correct ones. The program counts all correct and incorrect answers , tallies them, then reports the result. The program then asks the user whether to exit or run the tutorial again. Upon running the program, the user will be asked whether the beginner mode or advanced mode is to be used. The beginner mode presents problems that are relatively easy to answer and asks more addition and subtraction than multiplication and division. Advanced mode asks relatively harder questions. The user is then asked how many problems he/she wishes to answer. Ther eafte r, the progr am gene rate s enou gh rand om arith metic proble ms in the given diffic ulty level as specifie d by the user. You may work individually or by pair. IV. Implementation A tutorial program that generates the same problems over and over again each time you run it wil l obv iou sly be les s tha n use ful . This app lic ati on req uir es our program to generate (pseudo)random numbers. The following code illustrates how to do such in C. #include <stdlib.h> #include <time.h> int main() { int r1, r2, r3; srand( time(NULL) ); /*sets the seed to the current time*/ r1 = rand()%100+1; /* 1 <= r1 <= 100 */ r2 = rand()*100+1; /* 1 <= r2 <= 100, r2 is 'more' random than r1 */

Upload: wilmarc

Post on 30-May-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

 

ES 26 – Introduction to ProgrammingFirst Machine Problem

I. Project Title: Arithmetic Tutorial

II. Objectives

1. To learn the different facets of creating a C program.

2. To learn how to write structured and modular C programs.

III. Program Specifications

The goal of this project is for the student(s) to write a program that will serve

as a tutorial for people starting to learn basic arithmetic.

The program will present the user a series of arithmetic problems involving

two numbers and one of the four basic arithmetic operations (addition, subtraction,multiplication and division). The user tries to answer each problem and garners

“points” for correct ones. The program counts all correct and incorrect answers ,

tallies them, then reports the result. The program then asks the user whether to exit orrun the tutorial again.

Upon running the program, the user will be asked whether the beginner mode

or advanced mode is to be used. The beginner mode presents problems that are

relatively easy to answer and asks more addition and subtraction than multiplicationand division. Advanced mode asks relatively harder questions. The user is then asked

how many problems he/she wishes to answer. Thereafter, the program generatesenough random arithmetic problems in the given difficulty level as specified by the

user.

You may work individually or by pair.

IV. Implementation

A tutorial program that generates the same problems over and over again eachtime you run it will obviously be less than useful. This application requires our

program to generate (pseudo)random numbers. The following code illustrates how todo such in C.

#include <stdlib.h>

#include <time.h>

int main()

{

int r1, r2, r3;

srand( time(NULL) ); /*sets the seed to the current

time*/

r1 = rand()%100+1; /* 1 <= r1 <= 100 */

r2 = rand()*100+1; /* 1 <= r2 <= 100, r2 is 'more'

random than r1 */

 

r3 = rand()*50; /* 0 <= r3 < 50 */

return 0;

}

Repeatedly calling rand()will return a sequence of integers that has no

apparent order. You can use this to randomly generate operands and operators.

Note that srand(time(NULL)) has to be called only once, at the start of the

program before making any calls to rand(). Its job is to provide a random number

generator with a seed value taken from the current time stored in the computer’sclock. So unless you run the program at exactly the same time each day, the rand()

function will generate a different sequence of numbers every time.

One way by which you can make things easier for the user is to make sure that

your division problems have an integer quotient. You can’t really expect your target

user (e.g. children) to answer problems like 417 /324, do you?

Break up your program into functions so that it will be easier to write,

maintain and debug.

Assume that the user will always input integers but make sure to consider

other possible, yet avoidable, exceptions.

Lastly, additional enhancements to your program shall be added at your

discretion. Do not sacrifice the basic functionality of the project in favor of your add-ons.

V. Sample program execution (minimum)

C> atutor

Welcome to Narutard's Arithmetic Tutorial!

(B)eginner or (A)dvanced? B

How many problems? 3

What is 3 x 1? 3

What is 21 / 7? 7

What is 2 + 0? 2

You correctly answered 2 out of 3 problems, or 67%.

Do you wish to run the tutorial again (Y/N)? N

Thank you for using Narutard's Arithmetic Tutorial!

V. Documentation

The (external) documentation should explain how you conceptualized and

implemented your program. The document should contain the following:

1. Variables. Give brief descriptions on how you use them in the program.

2. Functions. Explain what each function does.

3. Algorithm of the program.

 

VI. Criteria for Grading

Functionality 50%Algorithm Design 25%External Documentation 15%User Interface 5%Code Readability 5%

100%

On this programming project, the grade will be reduced by 10% for every day latesubmission excluding weekends. Deductions will continue to accrue until the project is finallysubmitted (even if it results to a negative grade.) On the other hand, early submissions will begiven +2% for each day earlier than the due date (maximum of 10%).

VII. Deliverables

Submit the following on or before 4:50 pm of August 14, 2009 (Friday) at my

pigeon hole at Room 301, Engineering Library II Building:1. Fully documented source code and soft copy of your documentation (in pdf) in a CD.2. Printed external documentation. Do not submit printed copies of your source codes.3. Kindly place the above requirements in a short brown envelope with your respective

name(s), and sections, sealed with love and tape.

VIII. Other matters1. No extensions shall be given.2. No academic dishonesty will be tolerated. When in doubt ask.

 A novice asked the master: “I have a program that sometimes runs and sometimes aborts. I have followed therules of programming, yet I am totally baffled. What is the reason for this?”

The master replied: “You are confused because you do not understand Tao. Only a fool expects rational behaviorfrom his fellow humans. Why do you expect it from a machine that humans have constructed? Computers simulate

determinism; only Tao is perfect.”

“The rules of programming are transitory; only Tao is eternal. Therefore you must contemplate Tao before you

receive enlightenment.”

“But how will I know when I have received enlightenment?” asked the novice.

“Your program will then run correctly”, replied the master.

- 4.3, The Tao of Programming