Sie sind auf Seite 1von 3

Programming in C CS 49C Fall 2013

Homework Six
Please submit your solutions to the problems by 10:30 am (PST) on Thursday, October 31, 2013. Upload the source code (the .c files) at SJSU Canvas at https://sjsu.instructure.com/. Your programs should be able to compile and run in MS Visual Studio 2010. Problem 1 [Problem 16 on page 321] A password for a computer system must : 1) Have exactly 8 characters!2) Consist of only alphabetic characters and digits 3) Have at least one digit!4) Have at least one alphabetic character. Write a program (named hw6_1.c) to accept or reject a sequence of characters entered from the keyboard as a password. If the input does not meet the requirements for a password, have hw6_1.c ask for another attempt. If the input meets the requirement for a password, hw6_1.c should state that fact and terminate. Problem 2 [Problem 9 on page 376]!Write a recursive function

(named nthpower( ) ) that implements the recurrence relation to calculate the nth power of a floating point value x. Both, n and x should be parameters to nthpower( ). The return value of the function will be the value of xn.!To test nthpower( ), write a program (named hw6_2.c) to output the following table: Powers 1234567 ---------------------------------------------------------------------------1|1111111 Bases 2 | 2 4 8 16 32 64 128 3| 3 9 27 81 243 729 2187 and so on to some reasonable number n. Be careful of overflow errors. Problem 3 (Optional) [Modification of Problem 15 on page 378]!Write a program (named hw6_3.c) that will reserve seats on an airplane that has 10 first class seats and 100 coach seats. hw6_3.c is menu driven. The menu should give the following options: a. Reserve a first class seat on Flight 101 b. Reserve a coach seat on Flight 101!c. Quit If a seat of the desired type is available, hw6_3.c should record the reservation and display the seat number. If the user wants a first class seat and none are available, hw6_3.c should
2013 Sami Khuri Programming in C Fall 2013 CS 49C

inform the user that No first class seats are available and then display a menu with the following choices: a. Reserve a coach seat on Flight 101 b. Continue with other reservations!c. Quit

A similar menu should be displayed if the user wants a coach seat and one is not available. In other words, hw6_3.c should inform the user that No coach seats are available and then display a menu with the following choices: a. Reserve a first class seat on Flight 101 b. Continue with other reservations!c. Quit When all seats are taken, hw6_3.c should display: All seats are taken, try a later flight and terminate. Internally, an array of 10 elements should hold the reservation status for the first class seats. The array should be initialized with an a in each cell to indicate that the seat is available. When the seat is reserved, the a should be changed to an r. A similar array of 100 characters should hold the status of the coach seats. Make sure that hw6_3.c does not allocate a seat that is already taken.
2013 Sami Khuri 2
!