0% found this document useful (0 votes)
18 views4 pages

Workshop 04

workshop

Uploaded by

Nguyễn Trang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

Workshop 04

workshop

Uploaded by

Nguyễn Trang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Subject: PRF192- PFC

Workshop 04

Objectives:
(1) Managing data using pointers
(2) Developing programs using simple menus

Part 1: Use notebook

Exercise 1 (1 mark) : Explain outputs:

Exercise 2: (1 marks) What are outputs


Exercise 3: (2 marks) Walkthroughs
Part 2: Develop a program using simple menu

Program 1(3 marks):


Objectives Practice implementing a program with simple menu.
Related knowledge None
Problem Write a C program that will execute repetitively using a simple menu
as following:

1- Process PerfectSquareNumber
2- Print min, max digit in an integer;
3- Quit
Select an operation:

1- When user selects the option 1, the program will accept a non-
negative integer and print out a message about whether the
input number is a PerfectSquareNumber or not.
2- When user selects the option 2, the program will accept a
positive integral number and print out the minimum and
maximum digit in this number.
3- The program will terminate when user selects the option 3.

Analysis Nouns:
- non-negative integer  int n
- A number represents a choice of user  int choice;
Functions:
int PerfectSquareNumber ( int n)  see above
void printMinMaxDigits( int n)  see above
Suggested algorithm Begin
(logical order of Do /* Print out the menu and get user choice*/
verbs) { Print out “1- Process PerfectSquareNumber \n”;
Print out “2- Print min, max digit in an integer \n”;
Print out “3- Quit\n”;
Print out “Select an operation:”;
switch(choice)
{ case 1: do
{ Input n;
}
while(n<0);
If (PerfectSquareNumber (n)==1) Print “ It is a
PerfectSquareNumber\n”;
Else Print “ It is not a PerfectSquareNumber\n”;
break;
case 2: do
{ Input n;
}
while(n<0);
printMinMaxDigits( int n) ;
break;
}
}
while ( choice >0 & choice<3);
End

Program 2(3 marks): ( refer to the workshop 2 for algorithms)


Write a C program that will execute repetitively using a simple menu as following:

1-Fibonacci sequence
2-Check a date
3-Quit
Choose an operation:

1- When the option 1 is selected, the program will accept a positive integral number,
called as n, then the first n Fibonacci numbers will be printed out
2- When the option 2 is selected, the program will accept a date then the program will
tell that whether this data is valid or not.
3- If the option 3 is selected, the program quits

More Programs

You can pick 2 or 3 functions in the workshop 2, associate them to a new program.

You might also like