Main Page

Previous Page
Next Page

[Page 1270 (continued)]



Write a program that calculates the product of a series of integers that are passed to function product using a variable-length argument list. Test your function with several calls, each with a different number of arguments.


Write a program that prints the command-line arguments of the program.


Write a program that sorts an integer array into ascending order or descending order. The program should use command-line arguments to pass either argument -a for ascending order or -d for descending order. [Note: This is the standard format for passing options to a program in UNIX.]


Read the manuals for your system to determine what signals are supported by the signal-handling library (<csignal>). Write a program with signal handlers for the signals SIGABRT and SIGINT. The program should test the trapping of these signals by calling function abort to generate a signal of type SIGABRT and by pressing Ctrl+C to generate a signal of type SIGINT.

[Page 1271]

Write a program that dynamically allocates an array of integers using a function from <cstdlib>, not the new operator. The size of the array should be input from the keyboard. The elements of the array should be assigned values input from the keyboard. Print the values of the array. Next, reallocate the memory for the array to half of the current number of elements. Print the values remaining in the array to confirm that they match the first half of the values in the original array.


Write a program that takes two file names as command-line arguments, reads the characters from the first file one at a time and writes the characters in reverse order to the second file.


Write a program that uses goto statements to simulate a nested looping structure that prints a square of asterisks as shown in Fig. E.10. The program should use only the following three output statements:

     cout << '*';
     cout << ' ';
     cout << endl;


Provide the definition for union Data containing char charcter1, short short1, long long1, float float1 and double double1.


Create union Integer with members char charcter1, short short1, int integer1 and long long1. Write a program that inputs values of type char, short, int and long and stores the values in union variables of type union Integer. Each union variable should be printed as a char, a short, an int and a long. Do the values always print correctly?


Create union FloatingPoint with members float float1, double double1 and long double longDouble. Write a program that inputs values of type float, double and long double and stores the values in union variables of type union FloatingPoint. Each union variable should be printed as a float, a double and a long double. Do the values always print correctly?


Given the union

        union A
           double y;
           char *zPtr;

which of the following are correct statements for initializing the union?

  1. A p = b;   // b is of type A

  2. A q = x;   // x is a double

  3. A r = 3.14159;

  4. A s = { 79.63};

  5. A t = { "Hi There!" };

  6. A u = { 3.14159, "Pi" };

  7. A v = { y = 7.843 ,zPtr = &x };

Figure E.10. Example for Exercise E.8.

  *   *
  *   *
  *   *

Previous Page
Next Page