# include<string> #include <iostream> #include<cmath> #include <ctype.h> using namespace std; const int MAXITEMS= 5; int main() { cout<<"\n \t\t\t RANDOM SENTENCES\t\t\t"; cout<<"\n********************************************\n"; string article[MAXITEMS]={"the","a","one","some","any"}; string noun[MAXITEMS]={"boy","girl","dog","town","car"} ; string verb[MAXITEMS]={"drove","jumped","ran","walked ","skipped"} ; string preposition [MAXITEMS]={"to","from","over","under","on"}; int i=0; while (i<20){ int a=rand() % 5; int n=rand() % 5; int v=rand() % 5; int p=rand() % 5; string word= article[a]; word[0]= toupper(word[0]); cout <<" "<<i+1<<": "<<word <<" "<< noun[n]<< " "<< verb[v]<<" "<<preposition[p]<<"."<<endl; i++; } cout<<"\n********************************************\n\n"; return 0; } |
# include <iostream> # include <string> # include <cstdlib> # include <ctime> const int MAXN = 25; int rand1; void FirstDiagonal(int table[][MAXN],int N); void SecondDiagonal(int table[][MAXN],int N); void CenterElement(int table[][MAXN],int N); void BottomRightTriangle(int table[][MAXN],int N); void BottomLeftTriangle(int table[][MAXN],int N); void TopRightTriangle(int table[][MAXN],int N); void TopLeftTriangle(int table[][MAXN],int N); void LeftTriangle(int table[][MAXN],int N); void RightTriangle(int table[][MAXN],int N); void TopTriangle(int table[][MAXN],int N); void BottomTriangle(int table[][MAXN],int N); void SaveOriginalTable(int table[][MAXN], int temptable[][MAXN], int N); void RestoreOriginalTable(int table[][MAXN], int temptable[][MAXN], int N); void PrintArray(int table[][MAXN], int N); void menu(); using namespace std; int table[MAXN][MAXN], temptable[MAXN][MAXN]; int N; int main() { cout<<"PLease enter the odd integer between 3 and 21 : "; cin >> N; SaveOriginalTable( table, temptable, N); int choice; do { system ("cls"); cout << "\n Welcome to the two-dimentional array"; cout << "\n Please select one of these options"; cout << "\n 1- Change the first diagonal of the array to zero"; cout << "\n 2- Change the second diagonal of the array to zero"; cout << "\n 3- Change the center element of the array to zero"; cout << "\n 4- Change the bottom right triangle of the array to zero"; cout << "\n 5- Change the bottom left triangle of the array to zero"; cout << "\n 6- Change the top right triangle of the array to zero"; cout << "\n 7- Change the top left triangle of the array to zero"; cout << "\n 8- Change the left triangle of the array to zero"; cout << "\n 9- Change the right triangle of the array to zero"; cout << "\n 10- Change the top triangle of the array to zero"; cout << "\n 11- Change the bottom triangle of the array to zero"; cout << "\n 12- Print the original array " << "\n"; cout << "\n 13- Quit " << "\n"; cout << "\n Please type your choice : "; cin >> choice; if(choice==1) { FirstDiagonal(table, N); RestoreOriginalTable(table,temptable, N); } else if(choice==2) { SecondDiagonal(table, N); RestoreOriginalTable(table,temptable, N); } else if(choice==3) { CenterElement(table, N); RestoreOriginalTable(table,temptable, N); } else if(choice==4) { BottomRightTriangle(table, N); RestoreOriginalTable(table,temptable, N); } else if(choice==5) { BottomLeftTriangle(table, N); RestoreOriginalTable(table,temptable, N); } else if(choice==6) { TopRightTriangle( table, N); RestoreOriginalTable(table,temptable, N); } else if(choice==7) { TopLeftTriangle(table, N); RestoreOriginalTable(table,temptable, N); } else if(choice==8) { LeftTriangle(table, N); RestoreOriginalTable(table,temptable, N); } else if(choice==9) { RightTriangle(table, N); RestoreOriginalTable(table,temptable, N); } else if(choice==10) { TopTriangle( table, N); RestoreOriginalTable(table,temptable, N); } else if(choice==11) { BottomTriangle(table, N); RestoreOriginalTable(table,temptable, N); } else if(choice==12) { RestoreOriginalTable(table,temptable, N); PrintArray(table, N); } } while((choice>0)&&(choice<13)); system("pause"); return 0; } void FirstDiagonal(int table[][MAXN],int N) { for(int row=0;row<N;row++) for (int col=0;col<N;col++) if(row==col) table[row][col] = 0; PrintArray(table, N); } void SecondDiagonal(int table[][MAXN],int N) { for(int row=0;row<N;row++) for (int col=N-1; col>=0;col--) if((col+row)==N-1) table[row][col] = 0; PrintArray(table, N); } void CenterElement(int table[][MAXN],int N) { table[(N-1)/2][(N-1)/2] = 0; PrintArray(table, N); } void BottomRightTriangle(int table[][MAXN],int N) { for(int row=0;row<N;row++) for (int col=0;col<N;col++) if((row+col)>=(N-1)) table[row][col] = 0; PrintArray(table, N); } void BottomLeftTriangle(int table[][MAXN],int N) { for(int row=0;row<N;row++) for (int col=0;col<=(N-1)-((N-1)-row);col++) table[row][col] = 0; PrintArray(table, N); } void TopRightTriangle(int table[][MAXN],int N) { for(int row=0;row<N;row++) for (int col=row; col<N;col++) table[row][col] = 0; PrintArray(table, N); } void TopLeftTriangle(int table[][MAXN],int N) { for(int row=0;row<N;row++) for (int col=0;col<N;col++) if((row+col)<=(N-1)) table[row][col] = 0; PrintArray(table, N); } void LeftTriangle(int table[][MAXN],int N) { for(int row=0;row<N;row++) for (int col=row;col<N;col++) if((row+col)<=(N-1)) table[col][row] = 0; PrintArray(table, N); } void RightTriangle(int table[][MAXN],int N) { for(int row=0;row<N;row++) for (int col=row;col<N;col++) if((row+col)>=(N-1)) table[row][col] = 0; PrintArray(table, N); } void TopTriangle(int table[][MAXN],int N) { for(int row=0;row<N;row++) for (int col=row;col<N;col++) if((row+col)<=(N-1)) table[row][col] = 0; PrintArray(table, N); } void BottomTriangle(int table[][MAXN],int N) { for(int row=0;row<N;row++) for (int col=row;col<N;col++) if((row+col)>=(N-1)) table[col][row] = 0; PrintArray(table, N); } void SaveOriginalTable(int table[][MAXN], int temptable[][MAXN], int N) { srand(time(0)); for (int row=0 ; row<N; row++) { for (int col=0 ; col<N; col++) { rand1 = 1 + rand() % 9; table[row][col] = rand1; temptable[row][col] = table[row][col]; } } } void PrintArray(int table[][MAXN], int N) { system("cls"); for(int row=0; row<N; row++) { for (int col=0;col<N;col++) cout << table[row][col] << " "; cout << endl; } system("pause"); } void RestoreOriginalTable(int table[][MAXN], int temptable[][MAXN], int N) { for (int row=0;row<N;row++) { for ( int col=0;col<N;col++) { table[row][col] = temptable[row][col]; } } } |