help in writing 2 programes

hi

plz could any one solve these 2 C++ problems ?

i need the solutions before WED 03/03/13

thnx

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


1- Write a C++ program that uses random number generation to create sentences. Use four arrays of strings called article, noun, verb and preposition. Create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article and noun. As each word is picked concatenate in to previous words in the sentence. The words should be separated by spaces. When the final sentence is output, it should start with capital letter and end with a period. The program should generate 20 sentences and then print them to a screen. The arrays should be filled as follows: The article array should contain the articles "the", "a", "one", "some" and "any" ;the noun arrays should contain the nouns "boy" ,"girl" ,"dog" ,"town" and "car" ;the verb array should contain the past-tense verbs "drove" ,"jumped" ,"ran" ,"walked" and "skipped"; the preposition array should contain the prepositions "to" ,"from" ,"over" ,"under" and "on".
Hint: Use the following array declarations:-
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"};


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>



2- Write a C++ program that creates and manipulates an N×N dynamic two-dimensional array storing random positive numbers between 1 and 9. N is an odd integer between 3 and 21 entered by the user. Your program should offer the following menu options:
a- Change the first diagonal of the array to zero.
b- Change the second diagonal of the array to zero.
c- Change the center element of the array to zero.
d- Change the top right triangle of the array to zero.
e- Change the bottom left triangle of the array to zero.
f- Change the top left triangle of the array to zero.
g- Change the bottom right triangle of the array to zero.
h- Change the left triangle of the array to zero.
i- Change the right triangle of the array to zero.
j- Change the top triangle of the array to zero.
k- Change the bottom triangle of the array to zero.
l- Print the original Array.
Note: Your program should print the resulting array after each operation and then restore the original array before the next operation.
Hint: Use the following functions:-
a- void FirstDiagonal(int **table, int N);
b- void SecondDiagonal(int **table, int N);
c- void CenterElement(int **table, int N);
d- void TopRightTriangle(int **table, int N);
e- void BottomLeftTriangle(int **table, int N);
f- void TopLeftTriangle(int **table, int N);
g- void BottomRightTriangle(int **table, int N);
h- void LeftTriangle(int **table, int N);
i- void RightTriangle(int **table, int N);
j- void TopTriangle(int **table, int N);
k- void BottomTriangle(int **table, int N);
l- void PrintArray(int **table, int N);
m- void SaveOrginalTable(int **table, int **temptable, int N);
n- void RestoreOrginalTable(int **table, int **temptable, int N);


plz help :((
up ..

i finished solving both problems but these 4 function did not runed
plz i need only their definitions

c- Change the center element of the array to zero.
d- Change the top right triangle of the array to zero.
e- Change the bottom left triangle of the array to zero.
f- Change the top left triangle of the array to zero.

Hello
Here are my answers for those who want to benefit from these programes
All the best and thank you for your help!

for Q:1

# 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;
}



for Q:2

# 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];
}
}
}



I think there is no error in these solutions!
up up
Again,
read this post please before posting more: http://www.cplusplus.com/articles/Ny86b7Xj/
Topic archived. No new replies allowed.