/* QUESTION:
Double pointers use write a program to store alphabets to a table (length of table during program execution) using
double pointer. Pass the table as arguments to a function. Print the vowels to the screen.
Hint: Your will use new operator to allocate memory.
Note: You have to release the memory using delete operator before the end of program.
*/
// CODE :
#include<iostream>
using namespace std;
void find_vowels(char **ptr,int a,int b);
int main(){
int a,b;
cout<<"Enter the no of rows your table for storing alphabets ";
cin>>a;
char **ptr = new char *[a];
cout<<"Enter the no of coloumns";
cin>>b;
for (int i=0;i<a;i++){
ptr[i] = new char[b];
}
cout<<"\n\nEnter the characters\n";
for (int j=0;j<a;j++){
for(int k=0;k<b;k++){
cin>>ptr[j][k];
}
}
cout<<"\n The vowels out of table are\n\n";
find_vowels(ptr,a,b);
for(int p=0; p< a;p++)
delete [] ptr[p];
delete [] ptr;
return 0;
}
void find_vowels(char **ptr,int a,int b){
for (int l=0;l<a;l++){
for(int m=0;m<b;m++){
if (ptr[l][m] == 'a'||ptr[l][m] =='e'||ptr[l][m] =='i'||ptr[l][m] =='o'|| ptr[l][m] =='u'){
cout<<ptr[l][m]<<endl;
}
}
}
}
Double pointers use write a program to store alphabets to a table (length of table during program execution) using
double pointer. Pass the table as arguments to a function. Print the vowels to the screen.
Hint: Your will use new operator to allocate memory.
Note: You have to release the memory using delete operator before the end of program.
*/
// CODE :
#include<iostream>
using namespace std;
void find_vowels(char **ptr,int a,int b);
int main(){
int a,b;
cout<<"Enter the no of rows your table for storing alphabets ";
cin>>a;
char **ptr = new char *[a];
cout<<"Enter the no of coloumns";
cin>>b;
for (int i=0;i<a;i++){
ptr[i] = new char[b];
}
cout<<"\n\nEnter the characters\n";
for (int j=0;j<a;j++){
for(int k=0;k<b;k++){
cin>>ptr[j][k];
}
}
cout<<"\n The vowels out of table are\n\n";
find_vowels(ptr,a,b);
for(int p=0; p< a;p++)
delete [] ptr[p];
delete [] ptr;
return 0;
}
void find_vowels(char **ptr,int a,int b){
for (int l=0;l<a;l++){
for(int m=0;m<b;m++){
if (ptr[l][m] == 'a'||ptr[l][m] =='e'||ptr[l][m] =='i'||ptr[l][m] =='o'|| ptr[l][m] =='u'){
cout<<ptr[l][m]<<endl;
}
}
}
}
No comments:
Post a Comment