arrays.h?contains only function declarations (AKA prototypes)

#ifndef ARRAYS_H
#define ARRAYS_H

#include <fstream>
#include <string>
using namespace std;

const int SIZE = 60;

const int MAX_PRINTABLE_ASCII = '~';
const int MIN_PRINTABLE_ASCII = ' ';
const int ASCII_PRINTABLE_RANGE = MAX_PRINTABLE_ASCII - MIN_PRINTABLE_ASCII + 1;


// Requires: n must be > 0
// Modifies: nothing
// Effects: prints a right triangle
//  with a parameter of 3 gives
// Note: no spaces at the end of lines
//*
//**
//***
void printRight(int n);


// Requires: n must be > 0
// Modifies: nothing
// Effects: prints a right triangle upside down
//   with a parameter of 3 gives
// Note: no spaces at the end of lines
//***
// **
//  *
void printRight_upsideDown_rightJustified(int n);


// Requires: The size of array arr is size && size > 0 && size <= SIZE
// Modifies: Nothing
// Effects:  Prints the elements of the array to the monitor
//           Prints an endl at the end
//
//           e.g., If array a contains {'A','%','8'} then the following code:
//
//                 printArray(a,3);
//                 cout << "Hello";
//     will print:
//                 A%8
//                 Hello
// Note that there must be no space after the last element('8') in the above example
void printArray(const char arr[], int size);


// Requires: The size of array arr is rows x cols && rows > 0 && rows <= SIZE
//                                                && cols > 0 && cols <= SIZE
//
//           i.e., Even though array arr is allocated with SIZE rows, columns,
//                 it is a partially filled array
// Modifies: Nothing
// Effects:  Prints the elements of the array
//             one row per line
//           Prints an endl at the end
//
//           e.g., If array arr contains {{'A','3','@'}{'#','\','9'}}
//                  then the following code:
//
//                 printArray(arr,2,3);
//                 cout << "Hello";
//          will print:
//                 A3@
//                 #\9
//                 Hello
// Note: that there must be no spaces after '3' and '\' above
// Calls: printArray(const char arr[], int size);
void printArray(const char arr[][SIZE], int rows, int cols);


// Requires: The size of array arr is size && size > 0 && size <= SIZE
// Modifies: The array arr
// Effects:  Adds val to each character in the array
//           If the array is: how now brown cow
//           and val = 5,
//           then result is:  mt|%st|%gwt|s%ht|
// Note:     Make sure the character remains in the ' ' MIN_PRINTABLE_ASCII
//           to '~' MAX_PRINTABLE_ASCII range (inclusive)
//           all printable characters are between this range
//           If character < MIN_PRINTABLE_ASCII, then add ASCII_PRINTABLE_RANGE
//           If character > MAX_PRINTABLE_ASCII, then subtract ASCII_PRINTABLE_RANGE
//            to put back within range,  repeat as needed
//           all printable characters are between this range
//           ' ' is the 1st printable character (ASCII 32)
//           '~' is the last printable character (ASCII 126)
// Note:     Do not do the addition on char's. It could cause an overflow
void add(char arr[], int size, int val);


// Requires: The size of array arr is rows x cols && rows > 0 && rows <= SIZE
//                                                && cols > 0 && cols <= SIZE
// Modifies: The array arr
// Effects:  Adds val to each character in the array
//           If the array is the following:
//                     (note there are some spaces at the end of lines)
//           how
//           now
//           brown
//           cow
// with val = 5, the result would be
//           mt|%%
//           st|%%
//           gwt|s
//           ht|%%
// Note: Make sure the new character remains in the MIN_PRINTABLE_ASCII to
//           MAX_PRINTABLE_ASCII range (inclusive)
//           all printable characters are between this range
// Calls: void add(char arr[], int size, int val);
// Note:     Do not do the addition on char's. It could cause an overflow
void add(char arr[][SIZE], int rows, int cols, int val);


// Requires: The size of array arr is size && size > 0 && size <= SIZE
// Modifies: The array arr
// Effects:  Rotates the array by one element to the left
//           e.g., Array:  abcde when rotated left becomes: bcdea
void rotateLeft(char arr[], int size);


// Requires: The size of array arr is rows x cols && rows > 0 && rows <= SIZE
//                                                && cols > 0 && cols <= SIZE
// Modifies: The array arr
// Effects:  Rotates each row of the array by one element to the left
//           e.g., Array
//            abc
//            def
//            ghi
//          Result is:
//            bca
//            efd
//            hig
// Calls: void rotateLeft(char arr[], int size);
void rotateLeft(char arr[][SIZE], int rows, int cols);


// Requires: The size of array arr is size && size > 0 && size <= SIZE
// Modifies: The array arr
// Effects:  Rotates the array by one element to the right
//           e.g., Array: abcdef   when rotated right becomes: fabcde
void rotateRight(char arr[], int size);


// Requires: The size of array arr is rows x cols && rows > 0 && rows <= SIZE
//                                                && cols > 0 && cols <= SIZE
// Modifies: The array arr
// Effects:  Rotates each row of the array by one element to the right
//           e.g., Array
//            abc
//            def
//            ghi
//          Result is:
//            cab
//            fde
//            igh
// Calls: void rotateRight(char arr[], int size);
void rotateRight(char arr[][SIZE], int rows, int cols);


// Requires: The size of array arr is size && size > 0 && size <= SIZE
// Modifies: The array ar
// Effects:  Reverses the ordering of elements within the array
//           e.g., Array: abcdef when reversed becomes: fedcba
void reverse(char arr[], int size);


// Requires: arr1 to have size1 >= index1 + len  && size1 > 0 && size1 <= SIZE
//           arr2 to have size2 >= index2 + len && size2 > 0 && size2 <= SIZE
//           index1 must be within range of arr1
//           len >= 0
//           index1 + len - 1 must be within range of arr1
//           index2 must be within range of arr2
//           index2 + len - 1 must be within range of arr2
// Modifies: The array arr1 and array arr2
// Effects:  Swap elements of arr1 and elements of arr2 according to the following
//           elements of arr1 from arr1[index1] to arr1[index1+len-1] are swapped with
//           elements of arr2 from arr2[index2] to arr2[index2+len-1] inclusive
// Example:  if arr1 is: 123456 index1 = 0, len = 3
//              arr2 is: 789012 index2 = 3
//           the result is:
//           arr1 is: 012456       arr2 is: 789123
void swapRange(char arr1[], int size1, int index1,
               char arr2[], int size2, int index2, int len);


// Requires: The size of array arr is size &&  size > 0 && size <= SIZE && len > 0
// Modifies: The array arr
// Effects:  Exchanges len number of characters with the next len
//           number of characters continueing across the row.
//           If there isn't enough characters to do the exchange,
//           then exchange nothing.
// Example:  if the array is: batman$robin and len is 6, then batman is
//           exchanged with $robin resulting in: $robinbatman
//           if len is 3, then bat will exchange with man and
//              $ro will exchange with bin resulting in: manbatbin$ro
//           if len is 5, then batma will exchange with n$rob
//              resulting in: n$robbatmain
//           if len is 8, the exchange is not possible so do nothing
// Note: be careful you don't go outside bounds of the array on this one
// Calls: swapRange
void swapWithinOneRow(char arr[], int size, int len);


// Requires: The size of array arr is rows x cols && rows > 0 && rows <= SIZE
//                                                && cols > 0 && cols <= SIZE
// Modifies: The array arr
// Effects:  Will swap the row with index 0 with row index 1,
//                         row with index 2 with row index 3, etc
//           If n is odd, the last row will not be swapped
// Example:  if the array is
//         a b c
//         d e f
//         g h i
//       the result will be
//         d e f
//         a b c
//         g h i
// Calls: swapRange
void swapRows(char arr[][SIZE], int rows, int cols);


#endif
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末易迹,一起剝皮案震驚了整個濱河市斑鸦,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖涛贯,帶你破解...
    沈念sama閱讀 217,542評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異辈讶,居然都是意外死亡巫湘,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,822評論 3 394
  • 文/潘曉璐 我一進店門厕倍,熙熙樓的掌柜王于貴愁眉苦臉地迎上來寡壮,“玉大人,你說我怎么就攤上這事讹弯∥芟瘢” “怎么了?”我有些...
    開封第一講書人閱讀 163,912評論 0 354
  • 文/不壞的土叔 我叫張陵闸婴,是天一觀的道長坏挠。 經(jīng)常有香客問我,道長邪乍,這世上最難降的妖魔是什么降狠? 我笑而不...
    開封第一講書人閱讀 58,449評論 1 293
  • 正文 為了忘掉前任对竣,我火速辦了婚禮,結(jié)果婚禮上榜配,老公的妹妹穿的比我還像新娘否纬。我一直安慰自己,他們只是感情好蛋褥,可當我...
    茶點故事閱讀 67,500評論 6 392
  • 文/花漫 我一把揭開白布临燃。 她就那樣靜靜地躺著,像睡著了一般烙心。 火紅的嫁衣襯著肌膚如雪膜廊。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,370評論 1 302
  • 那天淫茵,我揣著相機與錄音爪瓜,去河邊找鬼。 笑死匙瘪,一個胖子當著我的面吹牛铆铆,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播丹喻,決...
    沈念sama閱讀 40,193評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼薄货,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了碍论?” 一聲冷哼從身側(cè)響起菲驴,我...
    開封第一講書人閱讀 39,074評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎骑冗,沒想到半個月后赊瞬,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,505評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡贼涩,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,722評論 3 335
  • 正文 我和宋清朗相戀三年巧涧,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片遥倦。...
    茶點故事閱讀 39,841評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡谤绳,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出袒哥,到底是詐尸還是另有隱情缩筛,我是刑警寧澤,帶...
    沈念sama閱讀 35,569評論 5 345
  • 正文 年R本政府宣布堡称,位于F島的核電站瞎抛,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏却紧。R本人自食惡果不足惜桐臊,卻給世界環(huán)境...
    茶點故事閱讀 41,168評論 3 328
  • 文/蒙蒙 一胎撤、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧断凶,春花似錦伤提、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,783評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至却嗡,卻和暖如春舶沛,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背稽穆。 一陣腳步聲響...
    開封第一講書人閱讀 32,918評論 1 269
  • 我被黑心中介騙來泰國打工冠王, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留赶撰,地道東北人舌镶。 一個月前我還...
    沈念sama閱讀 47,962評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像豪娜,于是被迫代替她去往敵國和親餐胀。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,781評論 2 354

推薦閱讀更多精彩內(nèi)容