Вы находитесь на странице: 1из 5

Swinburne University of Technology Sarawak Campus

Assignment 1
Fundamental programming concept, control
statements, and software design & testing
DEF117

S2, 2013
(1) Compose C statements to demonstrate how to make multiple call to scanf() function using a
while-loop.

(2) Compose C statements using nested for-loop to print out the ASCII table which contain a
numeric value and followed by a symbolic character.

(3) Draw the flow graph of the following C statements and determine the number of
independent paths of the program function.

Hint: reference - http://www.codeproject.com/Articles/37111/White-Box-Testing-Technique

#include<stdio.h>
#define MAX 9

void main()
{
int pw;
char ans;

printf(“ABC Trading Co.”); // Display Company Logo.


printf(“\n\nWelcome to the on-line management system..\n”); // Display welcome
msg.
Printf(“Please enter your passcard: ”); // prompt for user verification
scanf(“%d”, &pw); // read passcode
if (pw > 5000 || pw < 1) // passcode range verification
return; // exit program
do {
if (user_identification(pw) == 0) { // check user status
printf(“Error: no such person!!”); // display error msg – wrong person
return; // exit program
}
else
{
if (pw < 1000)
User_Clearance_Senior_Executive(); // Executive level functions.
else if (pw < 2000)
User_Clearance_Junior_Officer(); // Officer level functions.
else
User_Clearance_Operator(); // Operator level functions.
}
printf(“\nContinue <Y/N>? ”); // prompt to continue operation.
ans = getchar(); // read user decision
} while (ans == 'Y');
} //END of function program.

(4) A small program will prompt the user to key in a temperature value in degree Celsius and it
will convert the input value to degree Fahrenheit. This happens upon the ENTER key is strike
right after the input. The program will end when the user choose 'Y' to discontinue. It
happens right after each conversion happened. List down all possible input sets necessary to

1|Page
test the program. Provide the possible outputs for each sets of input and state the purpose
of the test sets.

Hint: reference - http://www.codeproject.com/Articles/37078/Black-box-Testing-Techniques

(5) What is the different between an integer variable and a character variable? Declare one
character variable and one integer variable.

(6) Declare and initialize a 16-bit real number variable that will store a numeric value -0.00102.

(7) What is the minimum character space an array will need to store a string valued “This is a
string… !”. Declare and initialize the said variable.

(8) Declare a suitable variable to store the following values:


a. 0x567
b. 123456
c. -0.6574
d. 11345.6457
e. “a”
f. ‘y’

(9) What is the different between a printf() and scanf() function?

(10)Write the C statements to show on the monitor/panel screen the value of the following
variable in predetermined form:
a. x = 123 in Hexadecimal form
b. x = 11345.6457 in this format: XXXXXXXXX.XX with leading zeroes.
c. x = “hello world!”, y = 012345, z = 0.1234 in this format:
|<10 spaces>hello world!<5 spaces>012345.00<5 spaces>0.123|

(11)Use scanf() function to capture the following values, write your answer in valid C codes:
a. -123
b. 123.0
c. Today is a good day!
d. Y

(12)Write a program to ask the program user to enter his/her personal information as listed in
below, then print the record on screen:
a. student name
b. student age
c. student address
You should decide on most suitable variable type and length to minimize the record size.

2|Page
(13)Declare a variable for each of the following data-type and store a value into it (through
simple assignment). Then using a standard library function to print out the value of each
variable on the monitor screen.
a. Character
b. Real number
c. Integer
d. String
e. Unsigned integer array

(14)Compose C statements to store and print the name of two friends of yours. Following is the
hinds for you to present your answers:
a. Store these names in two character arrays.
b. Initialize one of the strings with one of your friend’s name at the time you declare
the array.
c. Store another friend’s name in another string through standard input.
d. Print both names on the screen.

(15)Write a program that defines the ten digits, 0 through 9, as constants ZERO through NINE.
Add these ten defined digits together and print the result on the screen.
a. Hint: use pre-processor directive

(16)Compose C statements that will print each of the first 10 powers of 3. That is, 30, 31, 32, 33, …,
39. Include necessary in-line comments for those statements. Include your name at the top
of the program. Hints: Math operations

(17)Compose C statements that prompt the end-user for his or her full names (store each, first,
middle, and last name in separate character array). Get the input from the user for total
hours worked (H), hourly rates (R), and tax rates (Tr).
a. Compute the gross pay (G) by using the equation G = H * R.
b. Calculates the tax value (T) by equation T = G * Tr.
c. Calculate the Net pay (N) by equation N = G – T.
d. Display the Gross pay, Tax value, and net pay using appropriate dollars-and-cents
print codes (in ASCII table).

(18)Compose C statements that prompt the user for an employee’s pre-tax salary, and then print
the appropriate taxes. The taxes are 9% if the employee earned more than $3,000; 17% if
the employee gets more than $5,500 and less than $9,200. A 21% tax will be levied to the
employee earned more than and equals to $9,200. No tax is to be imposed for anyone
earned less than or equals to $3,000.

(19)Compose C statements to determine whether a user enters through keyboard an even


positive numbers using the IF-statement.

(20)Design the solution using flowchart and pseudo code for the following problems:
a. A program prompt for user input (numbers) and prints the error message if the input
is not a positive value.

3|Page
b. A repeated menu display with a keyboard input to choose any one item of the 4
items in the menu. The program only ends when user strikes the Escape key on the
keyboard.

(21)Translate the following pseudo code to standard C statement:


a. IF User_name EQUAL TO “Administrator” THEN
status_bit EQUAL TO 0
ELSE IF User_name EQUAL TO “Student” THEN
status_bit EQUAL TO 1
ELSE
DISPLAY error massage

Tips: Use strcmp() function to test the strings.

b. ASSIGN 5 to x
REPEAT
DISPLAY “Round number:” <tab> x
DISPLAY BLANK LINE
DECREMENT x
UNTIL x EQUAL TO ZERO

(22)Draw the flowchart for the case described below:


a. A repeated process that prompts the user for an integer input for ten rounds. The
total is computed during the process and it is printed to the user before the program
ended.
b. A simple process that prompt the user for temperature value in degree Celsius and
convert it to degree Fahrenheit using formula F = (5/6) * c + 32. Print the result on
the screen.

4|Page

Вам также может понравиться