Se183391 WS4
Se183391 WS4
Workshop 04
Objectives:
(1) Managing data using pointers
(2) Developing programs using simple menus
*pn = 7
*pm = 6
*pn = 6 + 2*6 - 3*7 = -3
*pm = *pm - *pn => *pm = 6 - (-3) = 9
=> m = 9, n = -3;
- m + n = 9 - 3 =6;
*p1 = A = 65;
*p2 = F = 70;
*p1 = *p1 + 3 = 65 + 3 = 68;
*p2 = *p2 - 5 = 70 - 5 = 65
=> c1 = 68, c2 = 65;
- c1 - c2 = 68 - 65 = 3
*p1 = 3.2;
*p2 = 5.1;
*p1 = *p1 + 3 - 2*(*p2) =3.2 + 3 - 2*5.1 = -4;
*p2 = *p2 - 3*(*p1) = 5.1 - 3*3.2 = 17.1
=> x= -4, y= 17.1;
- x + y= -4 + 17.1 = 13.1
1- Process primes
2- Print min, max digit in an integer;
3- Quit
Select an operation:
Analysis Nouns:
- positive integral number int n
- A number represents a choice of user int choice;
Functions:
int prime( 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 primes\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 ( prime(n)==1) Print “ It is a prime\n”;
Else Print “ It is not a prime\n”;
break;
case 2: do
{ Input n;
}
while(n<0);
printMinMaxDigits( int n) ;
break;
}
}
while ( choice >0 & choice<3);
End
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.