D
DaveC
Hi.. I have a C exam in a few days.. Looking back at old exams I find a few
things we have not been taught / cant remember being taught. Below is a
question from last year.
My question is how do you align values and define field widths in the
printf function? I'm ok with the rest of the question.
Thanks
DaveC
(a) Declare a C structure that can contain data describing a computer.
The structure contains the following: the speed of the processor in GHz (a
floating point number), the amount of RAM in Mbytes (an integer), the size
of
the hard disk in Gbytes (an integer), the type of processor (a string) and
the
name of the manufacturer (a string). [2 marks]
(b) Declare a global variable of the above structure, and initialise it
with
reasonable values. (Do not use assignment statements.) [1 mark]
(c) Write C code for a function print_computer , that has a single argument
(a
pointer to a structure describing the computer).
The function prints the computer details on one line as follows:
The manufacturer left aligned in a field width of 30,
The processor type right aligned in a field width of 12,
The processor speed right aligned in a field width of 8 (1 decimal place),
The RAM size right aligned in a field width of 6,
The hard disk size right aligned in a field width of 6. [3 marks]
things we have not been taught / cant remember being taught. Below is a
question from last year.
My question is how do you align values and define field widths in the
printf function? I'm ok with the rest of the question.
Thanks
DaveC
(a) Declare a C structure that can contain data describing a computer.
The structure contains the following: the speed of the processor in GHz (a
floating point number), the amount of RAM in Mbytes (an integer), the size
of
the hard disk in Gbytes (an integer), the type of processor (a string) and
the
name of the manufacturer (a string). [2 marks]
(b) Declare a global variable of the above structure, and initialise it
with
reasonable values. (Do not use assignment statements.) [1 mark]
(c) Write C code for a function print_computer , that has a single argument
(a
pointer to a structure describing the computer).
The function prints the computer details on one line as follows:
The manufacturer left aligned in a field width of 30,
The processor type right aligned in a field width of 12,
The processor speed right aligned in a field width of 8 (1 decimal place),
The RAM size right aligned in a field width of 6,
The hard disk size right aligned in a field width of 6. [3 marks]