[ back to toc ]

C Project

Date: 2002/05/08 09:20

Dear Peter,I have this Project I have to complete and I am totally stuck
on it. Could you please point me in the right direction with it. I'm not
trying to get you to do it all, but I really do need some pointers as to
which direction I need to go .

Many Thanks, *NAME-DELETED*.

Here goes,

Part 1

A company running a small furniture warehouse does a stock check at
regular intervals. Each type of stock item has a stock number. These are
consecutive and between 1 and 10. During the stock check the number of
items in stock is recorded against the stock number. The company requires
a program which will display a stock report.

A program should be written in which the name of the company should be
entered at the keyboard. The wholesale price of each stock item should be
held in an array. The program should accept the number in stock for each
item and store them in a corresponding array.

It should then,
1) List the stock number, the number in stock and the price of each item
in the form of a table. Each column of figures should have a heading.
2) List the stock numbers of items out of stock.
3) Display the stock number and price of the highest priced item,and of
the lowest priced item, assuming all prices are different.
4) Display the total wholesale value of the stock.
The output from each section of the program should appear on a cleared
screen with the company name at the top.

Devise a series of test runs to thoroughly test the program. For each one,
a) Write down and explain your choice of test values used for the
name,prices and the numbers in stock.
b) Write down the expected results.Justify the results showing
calculations and comparisons made,where necessary.

Program Design a) Produce a table of identifiers.
b) Using stepwise refinement produce an algorith for the program,written
in pseudo-code.
Coding - from your pseudo-code,write the program in C.
Testing - using your test plan,run and debug the program.

Part 2

It has been decided that some of the methods used in this program should
be written within general purpose functions for use in other programs. The
variable names should be generalised and any output annotations should be
kept to the main program.
Alter your program to contain these functions. Global variables should not
be used. Values should be passed between functions using parameters and
the return function.

a) to be able to display the highest and lowest prices, write a general
purpose function.


which receives an array of floating point numbers and the size of the
array as parameters, finds the highest and lowest integers in the array
and returns their values to the calling function.
b) to be able to display the stock numbers of out-of-stock items, write a
general purpose function.


which receives an array of floating point numbers, the size of an array
and an integer as parameters and outputs the position or positions of that
integer in the array.
c) to be able to output each section of the program on a cleared screen,
write a function,


which accepts a character array(or string)as a parameter, clears the
screen and outputs the string at the centre of the top of the screen.
Well, this is quite general, thus I could say: learn programming in C. But
I do not want to make you angry with such a sarcastic answer.

There are certainly main issues that you can first focus on:

1.) Getting input from the keyboard. This needs scanf fucntion to be used.

2.) Printing things to the screen. This needs printf.

3.) Storing things in files as database. This needs fprintf, fopen,
fclose, fgets, fscanf and alike functions.

I would recommend that you start learning these functions. After having
practiced with these (a week or two) you have to design the data structure
that you will store the data in files. Then you can write the first
programs related to the issue. I recommend that you write the simplest
sub-task first.


[ back to toc ]