<< Chapter < Page Chapter >> Page >

5) A prime integer is any integer that is evenly divisible only by itself and 1. The Sieve of Eratosthenes is a method of finding prime numbers. It operates as follows:

  1. Create an array with all elements initialized to 1 (true). Array elements with prime subscripts will remain 1. All other array elements will eventually be set to zero.
  2. Starting with array subscript 2 (subscript 1 must be prime), every time an array element is found whose value is 1, loop through the remainder of the array and set to zero every element whose subscript is a multiple of the subscript for the element with value 1. For array subscript 2, all elements beyond 2 in the array that are multiple of 2 will be set to zero (subscript 4, 6, 8, 10,etc.); for array subscript 3, all elements beyond 3 in the array that are multiple of 3 will be set to zero (subscripts 6, 9, 12, 15, etc.); and so on.

When this process is complete, the array elements that are still set to one indicate that the subscript is a prime number. These subscripts can then be printed.

Write and run a C++ program that uses an array of 1000 elements to determine and print the prime numbers between 1 and 999. Ignore element 0 of the array.

6) The Colossus Airlines fleet consists of one plane with a seating capacity of 12. It makes one flight daily. Write a seating reservation program with the following features:

a. The program uses an array of 12 structures. Each structure should hold a seat identification number, a marker that indicates whether the seat is assigned and the name of the seat holder. Assume that the name of a customer is not more than 20 characters long.

b. The program displays the following menu:

  1. Show the number of empty seats
  2. Show the list of empty seats.
  1. Show the list of customers together with their seat numbers in the order of the seat numbers
  2. Assign a customer to a seat
  3. Remove a seat assignment
  4. Quit

c. The program successfully executes the promises of its menu. Choices (4) and (5) need additional input from the user, which is done inside the respective functions.

d. After executing a particular function, the program shows the menu again, except for choice (6).

7) In this problem, a customer calls in an order for bicycles, giving his or her name, address, number of bicycles desired, and the kind of bicycle. For now, all bicycles on one order must be the same kind. Mountain bikes cost $269.95 each and street bikes $149.50. The total bill is to be calculated for the order. Additionally, based on the user’s knowledge of the customer, the customer is classified as either a good or bad credit risk. Based on the input data, the program is to prepare shipping instructions listing the customer’s name, address, number and type of bikes, and the total amount due. Based on the creditworthiness of the customer, the program must indicate on the shipping instructions if this is a C.O.D. (cash on delivery) shipment or whether the customer will be billed separately.

The input and output requirements of this problem are relatively simple. On the input side, the items that must be obtained are:

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Programming fundamentals in c++. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10788/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Programming fundamentals in c++' conversation and receive update notifications?

Ask