1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
//-----------------------------------------------------------------------
//
// Name : >>>> DO_1 <<<<<<
//
// // Purpose: This program reads in four characters and then
// prints them out in a rotated pattern. When done rotating
// the four characters, it will read another four characters
// and rotate them. It repeats this process of reading and
// rotating until end-of-file
//
// Input : Four characters c1, c2, c3, and c4.
//
// Output : The four character in a rotated pattern. For example, if
// the characters are A B C D the output is:
// ABCD
// BCDA
// CDAB
// DABC
//
//-----------------------------------------------------------------------
#include <iostream>
using namespace std;
const int NUM_STEPS = 4; // number of rotation steps to perform
void DisplayRotationPattern(char c1, char c2, char c3, char c4);
void DisplayFourChars(char c1, char c2, char c3, char c4);
// DO_2: Complete the following function prototype.
// This function "rotates" four characters c1, c2, c3, and c4.
// That is, it puts c2 in c1, c3 in c2, c4 in c3, and c1 in c4.
void RotateFourChars(char c1, char c2, char c3, char c4);
int main()
{
char ch1, ch2, ch3, ch4;
cout << "Enter four characters: ";
cin >> ch1 >> ch2 >> ch3 >> ch4;
while( cin )
{
cout << "The Rotation patterns are:" << endl;
// DO_3: Call DisplayRotationPattern
cout << "Enter four characters: ";
cin >> ch1 >> ch2 >> ch3 >> ch4;
}
return 0;
}
//-----------------------------------------------------------------------
// This function displays the four characters passed to it
// in a rotated pattern.
// params: (in, in, in, in)
//-----------------------------------------------------------------------
void DisplayRotationPattern(char c1, char c2, char c3, char c4)
{
int count = 1;
while (count <= NUM_STEPS)
{
// DO_4: Call function to display the characters
cout << endl;
// DO_5: Call function to rotate the characters
count ++;
}
}
//-----------------------------------------------------------------------
// This function "rotates" four characters c1, c2, c3, and c4.
// That is, it puts c2 in c1, c3 in c2, c4 in c3, and c1 in c4.
// params: (inout, inout, inout, inout)
//-----------------------------------------------------------------------
//
// DO_6: Write the function header
void RotateFourChars( )
{
// DO_7: Write the function body.
}
//-----------------------------------------------------------------------
// This function has four input parameters, each of them is a character.
// The function displays the four characters at the beginning of a line.
// params: (in, in, in, in)
//-----------------------------------------------------------------------
void DisplayFourChars(char c1, char c2, char c3, char c4)
{
// DO_8: Write function body
}
|