1.

Define a function to input a list of names and store them as dynamically-allocated strings in an array, and a function to output them:

  • void ReadNames (char *names[], const int size);
  • void WriteNames (char *names[], const int size);

Write another function which sorts the list using bubble sort:

void BubbleSort (char *names[], const int size);

Bubble sort involves repeated scans of the list, where during each scan adjacent items are compared and swapped if out of order. A scan which involves no swapping indicates that the list is sorted.

2.

Write a program to add two fractions and display the result fraction. Your program will prompt the user to input fraction 1 and fraction 2. The numerator and denominator of each fraction are input separately by space.  See the sample output below. You will need to use a C++ structure to define a fraction. The structure has two members: numerator and denominator.

Example:
Fraction 1 Numerator - 5
Fraction 1 Denomenator - 6

Fraction 1 Numerator - 3
Fraction 1 Denomenator - 6

Output : - 4/3

3.

Write a program that reads values for the length and width of a rectangle and displays the perimeter and area of the rectangle.

A sample output is shown below:
 

Length = 25

Width = 14

Perimeter is 78

Area is 350

4.

Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For division, if the denominator is zero, output an appropriate message.) Some sample outputs follow:

 

3 + 4 = 7

13 * 5 = 65

5.

Write a program that reads in the size of the side of a square and then prints a hollow square of that size out of asterisks and blanks. Your program should work for squares of all side sizes between 1 and 20.
For example, if your program reads a size of 5, it should print:

*****
*    *
*    *
*    *
*****

6.

Write a program that calculates and displays the product of three integers. Add comments to the code where appropriate. [Note: You’ll need to write the necessary using directives.]
 

A sample output is shown below:
 

Enter three integers:

12

15

6

The product is 1080

7.

Write a program that converts length entered in meters to feet. The length in meters is to be entered by the user. Remember 1 feet = 3.28 meters.

A sample output is shown below:

Length in meters: 24

Length in feet: 78.72

8.

Write a program that inputs a five-digit number, separates the number into its individual digits and prints the digits separated from one another by three spaces each.

A sample output is shown below:

Enter a five-digit number: 54310
5 4 3 1 0
9.

Write a program which inputs a positive integer n and outputs 2 raised to the power of n.

Hint:

Use bitwise operator

In a byte, each successive bit corresponds to a value of 2 raised to a power, starting from 20 on the right, to 27 on the left, as shown in following figure.

http://ptgmedia.pearsoncmg.com/images/chap3_9780321877581/elementLinks/03fig01_alt.jpg

 

A sample output is shown below:

What is the value of n (Positive integer only)? 3
2 to the power of 3 = 8

 

10.

Write a program to swap two variables without using third or temp variable.

A sample output is shown below:
 

Enter value for first integer:  22

Enter value for second integer:  55

Values Before swapping:

First Integer =22

Second Integer =55

Values After swapping:

First Integer =55

Second Integer =22