Description
1. Write a C++ program file consisting of the following functions to create a library. You are
not allowed to use any standard library function. Also, do not include the function main()
in this file.
• int printStringUpper (char *) – print a string of characters terminated by ‘\0’,
where all the alphabetic characters are printed in uppercase. The return value is the
number of characters printed (excluding the ‘\’ character).
• int readHexInteger (int *n) – read a signed hexadecimal integer in ‘%x’ format,
convert it to decimal, and pass the value through the pointer parameter. The return
value is GOOD (for success) or BAD (on failure).
• int printHexInteger (int n) – print the (signed) decimal integer n in left-aligned
hexadecimal form. A negative number must be preceded by the minus sign; whereas no
prefix is required for non-negative numbers. For example, the number -65529 will be
printed as –FFF9. On success, the function will return the number of characters printed,
and on failure it will return BAD.
• int readFloat (float *f) – read a floating point number in ‘%f’ format (for example,
–123.456), where the value is passed through the pointer parameter. The return value
is GOOD or BAD.
• int printFloat (float f) – print the floating point number f in left-aligned form.
Printing sign for a negative number is mandatory while for a positive number it is not
required. There must be a mandatory decimal point in the output (for example, 25 will
be printed as 25.). On success, the function will return the number of characters printed,
and on failure it will return BAD.
Use the following header file for your C++ program.
/* Header file for Assignment 2: Name it as “toylib.h” */
#ifndef TOYLIB H
#define TOYLIB H
#define BAD -1
#define GOOD 1
int printStringUpper (char *);
1
int printHexInteger (int);
int readHexInteger (int *);
int readFloat (float *);
int printFloat (float);
#endif
2. Name your source file as ass2 roll.cpp (where roll is your roll number), which must include
only “toylib.h” as the header file, and should not contain the function main(). Write the
main() function in a separate file, and use Makefile to test your library.
For submission, move the main.c, toylib.h, Makefile and ass2 roll.cpp in a folder asgn2 roll.
Zip the folder and upload the file asgn2 roll.zip on the moodle server.
Marking scheme: Each function will carry equal weight. There will be a penalty of 10 marks
if Makefile is not provided.
2