Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C++, follow the instructions! When you do the swap, you may NOT hard code the swap. You have to use some loop that moves

image text in transcribed

Use C++, follow the instructions! When you do the swap, you may NOT hard code the swap. You have to use some loop that moves through the array and figures out when/where to swap. Show the program compiles and runs.

#include

#include

#define NUM_COLS 5

#define NUM_ROWS 5

using namespace std;

void displayMenu(){

cout

cout

cout

cout

cout

cout

}

void interchangeCols(char array[][NUM_COLS]){

for(int i=0;i

//swapping elements at column 2 (index 1) and column 5 (index 4)

char temp=array[i][1];

array[i][1]=array[i][4];

array[i][4]=temp;

}

}

void countVowels(char array[][NUM_COLS]){

int count=0;

for(int i=0;i

for(int j=0;j

char c=array[i][j];

if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u'){

//lower case vowel

count++;

}else if(c=='A' || c=='E' || c=='I' || c=='O' || c=='U'){

//upper case vowel

count++;

}

}

}

cout

}

void display(char array[][NUM_COLS]){

cout

for(int i=0;i

for(int j=0;j

char c=array[i][j];

cout

}

cout

}

cout

}

void search(char array[][NUM_COLS]){

char c;

//getting character to search

cout

cin>>c;

int count=0;

for(int i=0;i

for(int j=0;j

if(c==array[i][j]){

//found, updating count

count++;

}

}

}

cout

}

int main(){

char array[NUM_ROWS][NUM_COLS]={

{ 's','l','o','a','n'},

{'h','o','r','s','e'},

{'e','g','r','i','t'},

{'h','o','u','s','e'},

{'w','a','t','e','r'}

};

int choice=0;

while(choice!=5){

//displaying menu, getting choice

displayMenu();

cin>>choice;

//handling choice

switch(choice){

case 1: interchangeCols(array);

cout

break;

case 2: countVowels(array);

break;

case 3: display(array);

break;

case 4: search(array);

break;

}

} return 0;

}

Functional Requirements: Same program requirements as Chapter 6/7 except rewrite your program to utilize pointer addressing instead of array subscripting Programming Requirements: 1. Declare a char array and initialize it as before. (You can't point at a 2D array in C++, so create an 1-dim array with 25 elements.) 2. Declare an char pointer and point to the array. From then on in the program, you may only use the pointer You may not use the array or any array subscripting in any other part of your program You must only use pointer addressing You must use functions as before - but this time, pass the pointer instead of the array 3. Always display the array and manipulate it as if it were still a 2-dim array of 5x5 4. Make sure variables. Use functions and parameters appropriately r code is well-organized and well-documented. No global Programming Notes: You will want to fix any errors that you may have had in the Chapter 6&7 review so that you don't get dinged twice. Toward that end, i will release a Good Example of the Lesson 6&7 program no later th sure to take a look at that before you submit this assignment. "2/23" for your review. Be Here's a smaller example of what I mean about setting up the pointer and not using array subscripts char balance[4] ['a', 'b', 'c', 'd'); //here I am declaring my array char 'pointI/ declaring the pointer point balance; //pointing to the array for (int i 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago