SlideShare a Scribd company logo
1 of 2
Using C++11: Write a function that takes a char array as an input parameter and reverses the
string. The function should use two pointers, front and rear. The frontpointer should initially
reference the first character in the string, and the rear pointer should initially reference the last
character in the string. Reverse the string by swapping the characters referenced by front and
rear, then increment front to point to the next character and decrement rear to point to the
preceding character, and so on, until the entire string is reversed.
Then, write a main function that takes a string as input from the user and prints the reversed
string (using the above function). All input strings will be 100 characters or fewer.
You must use pointers to reverse the array.
If you use dynamic arrays (not required), you must delete all memory allocated to any dynamic
arrays before the program ends.
The program should print a string of text to the terminal before getting each line of input from
the user. A session should look like one of the following examples (including whitespace and
formatting), with possibly different numbers in the output:
The strings printed by the program should include a newline at the end.
Solution
#include <iostream>
#include <cstring>
using namespace std;
string reverse(char word[20]);
int main()
{
char string[20];
cout<<"enter a word: ";
cin>>string;
string results = reverse(string);
cout <<results;
}
string reverse(char word[20])
{
char a='a';
char b='b';
char *front=&a;
char *rear=&b;
for (int i=0;i< (strlen(word)/2);i++)
{
front[0]=word[i];
rear[0]=word[strlen(word)-1-i];
word[i]=*rear;
word[strlen(word)-1-i]=*front;
}
return word;
}

More Related Content

Similar to Using C++11- Write a function that takes a char array as an input para.docx

Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSivakumar R D .
 
Format string
Format stringFormat string
Format stringVu Review
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingAMAN ANAND
 
Instructions Write a program whose main function is merely a.pdf
Instructions Write a program whose main function is merely a.pdfInstructions Write a program whose main function is merely a.pdf
Instructions Write a program whose main function is merely a.pdfadinathknit
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docxwilcockiris
 
The Input Statement in Core Python .pptx
The Input Statement in Core Python .pptxThe Input Statement in Core Python .pptx
The Input Statement in Core Python .pptxKavitha713564
 
Input and output in c++
Input and output in c++Input and output in c++
Input and output in c++Asaye Dilbo
 
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdfUsing the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdfamirthagiftsmadurai
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And OutputLISP Content
 
Write a parallel program using MPI and not OpeMP to accomp.pdf
Write a parallel program using MPI and not OpeMP to accomp.pdfWrite a parallel program using MPI and not OpeMP to accomp.pdf
Write a parallel program using MPI and not OpeMP to accomp.pdfaaryanentp
 

Similar to Using C++11- Write a function that takes a char array as an input para.docx (13)

Function
FunctionFunction
Function
 
Input-output
Input-outputInput-output
Input-output
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
 
Format string
Format stringFormat string
Format string
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Instructions Write a program whose main function is merely a.pdf
Instructions Write a program whose main function is merely a.pdfInstructions Write a program whose main function is merely a.pdf
Instructions Write a program whose main function is merely a.pdf
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
 
The Input Statement in Core Python .pptx
The Input Statement in Core Python .pptxThe Input Statement in Core Python .pptx
The Input Statement in Core Python .pptx
 
Input and output in c++
Input and output in c++Input and output in c++
Input and output in c++
 
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdfUsing the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
 
Write a parallel program using MPI and not OpeMP to accomp.pdf
Write a parallel program using MPI and not OpeMP to accomp.pdfWrite a parallel program using MPI and not OpeMP to accomp.pdf
Write a parallel program using MPI and not OpeMP to accomp.pdf
 

More from slyndon

Use the Referraces to acce inportant val In the following net ionic eq.docx
Use the Referraces to acce inportant val In the following net ionic eq.docxUse the Referraces to acce inportant val In the following net ionic eq.docx
Use the Referraces to acce inportant val In the following net ionic eq.docxslyndon
 
Use the References to access importantv It is often possible to change.docx
Use the References to access importantv It is often possible to change.docxUse the References to access importantv It is often possible to change.docx
Use the References to access importantv It is often possible to change.docxslyndon
 
Use the following financial statements for Lake of Egypt Marina- Inc-.docx
Use the following financial statements for Lake of Egypt Marina- Inc-.docxUse the following financial statements for Lake of Egypt Marina- Inc-.docx
Use the following financial statements for Lake of Egypt Marina- Inc-.docxslyndon
 
Use SQL to Create a table with at least 4 attributes one of which is t.docx
Use SQL to Create a table with at least 4 attributes one of which is t.docxUse SQL to Create a table with at least 4 attributes one of which is t.docx
Use SQL to Create a table with at least 4 attributes one of which is t.docxslyndon
 
Using your own words and one complete sentence per term- define the fo.docx
Using your own words and one complete sentence per term- define the fo.docxUsing your own words and one complete sentence per term- define the fo.docx
Using your own words and one complete sentence per term- define the fo.docxslyndon
 
Using the method of 1-2 reactions balance the skeleton equation- I2 +.docx
Using the method of 1-2 reactions balance the skeleton equation- I2 +.docxUsing the method of 1-2 reactions balance the skeleton equation- I2 +.docx
Using the method of 1-2 reactions balance the skeleton equation- I2 +.docxslyndon
 
Using the descriptions of the attributes given in the ERD below- provi.docx
Using the descriptions of the attributes given in the ERD below- provi.docxUsing the descriptions of the attributes given in the ERD below- provi.docx
Using the descriptions of the attributes given in the ERD below- provi.docxslyndon
 
Using the following definition for a Binary Tree Node - complete the f.docx
Using the following definition for a Binary Tree Node - complete the f.docxUsing the following definition for a Binary Tree Node - complete the f.docx
Using the following definition for a Binary Tree Node - complete the f.docxslyndon
 
using the concepts of bonding and polarity explaining the importance o.docx
using the concepts of bonding and polarity explaining the importance o.docxusing the concepts of bonding and polarity explaining the importance o.docx
using the concepts of bonding and polarity explaining the importance o.docxslyndon
 
Using the competing values framework as a point of reference- how woul.docx
Using the competing values framework as a point of reference- how woul.docxUsing the competing values framework as a point of reference- how woul.docx
Using the competing values framework as a point of reference- how woul.docxslyndon
 
Using jsfiddle-net In Javascript we are going to create a doubly Linke.docx
Using jsfiddle-net In Javascript we are going to create a doubly Linke.docxUsing jsfiddle-net In Javascript we are going to create a doubly Linke.docx
Using jsfiddle-net In Javascript we are going to create a doubly Linke.docxslyndon
 
Using Haskell- I need- -- - Produce a list where sequences of repeated.docx
Using Haskell- I need- -- - Produce a list where sequences of repeated.docxUsing Haskell- I need- -- - Produce a list where sequences of repeated.docx
Using Haskell- I need- -- - Produce a list where sequences of repeated.docxslyndon
 
Using Java- Windows on the desktop are just one of many objects used i.docx
Using Java- Windows on the desktop are just one of many objects used i.docxUsing Java- Windows on the desktop are just one of many objects used i.docx
Using Java- Windows on the desktop are just one of many objects used i.docxslyndon
 
Using examples describe five major reasons for segregation of duties w.docx
Using examples describe five major reasons for segregation of duties w.docxUsing examples describe five major reasons for segregation of duties w.docx
Using examples describe five major reasons for segregation of duties w.docxslyndon
 
Using Java- Evaluate the expression- Be sure to list a value of approp.docx
Using Java- Evaluate the expression- Be sure to list a value of approp.docxUsing Java- Evaluate the expression- Be sure to list a value of approp.docx
Using Java- Evaluate the expression- Be sure to list a value of approp.docxslyndon
 
Using Java- code a dynamic Linear Quotient Hashing data structure that.docx
Using Java- code a dynamic Linear Quotient Hashing data structure that.docxUsing Java- code a dynamic Linear Quotient Hashing data structure that.docx
Using Java- code a dynamic Linear Quotient Hashing data structure that.docxslyndon
 
using C++ to Write a program to demonstrate an array of 10 elements an.docx
using C++ to Write a program to demonstrate an array of 10 elements an.docxusing C++ to Write a program to demonstrate an array of 10 elements an.docx
using C++ to Write a program to demonstrate an array of 10 elements an.docxslyndon
 
Using complete sentences- briefly answer the following- A) Accurately.docx
Using complete sentences- briefly answer the following- A) Accurately.docxUsing complete sentences- briefly answer the following- A) Accurately.docx
Using complete sentences- briefly answer the following- A) Accurately.docxslyndon
 
Using a practical example- what are the benefits and potential problem.docx
Using a practical example- what are the benefits and potential problem.docxUsing a practical example- what are the benefits and potential problem.docx
Using a practical example- what are the benefits and potential problem.docxslyndon
 
User Interface Engneering A company is designing a kiosk that can disp.docx
User Interface Engneering A company is designing a kiosk that can disp.docxUser Interface Engneering A company is designing a kiosk that can disp.docx
User Interface Engneering A company is designing a kiosk that can disp.docxslyndon
 

More from slyndon (20)

Use the Referraces to acce inportant val In the following net ionic eq.docx
Use the Referraces to acce inportant val In the following net ionic eq.docxUse the Referraces to acce inportant val In the following net ionic eq.docx
Use the Referraces to acce inportant val In the following net ionic eq.docx
 
Use the References to access importantv It is often possible to change.docx
Use the References to access importantv It is often possible to change.docxUse the References to access importantv It is often possible to change.docx
Use the References to access importantv It is often possible to change.docx
 
Use the following financial statements for Lake of Egypt Marina- Inc-.docx
Use the following financial statements for Lake of Egypt Marina- Inc-.docxUse the following financial statements for Lake of Egypt Marina- Inc-.docx
Use the following financial statements for Lake of Egypt Marina- Inc-.docx
 
Use SQL to Create a table with at least 4 attributes one of which is t.docx
Use SQL to Create a table with at least 4 attributes one of which is t.docxUse SQL to Create a table with at least 4 attributes one of which is t.docx
Use SQL to Create a table with at least 4 attributes one of which is t.docx
 
Using your own words and one complete sentence per term- define the fo.docx
Using your own words and one complete sentence per term- define the fo.docxUsing your own words and one complete sentence per term- define the fo.docx
Using your own words and one complete sentence per term- define the fo.docx
 
Using the method of 1-2 reactions balance the skeleton equation- I2 +.docx
Using the method of 1-2 reactions balance the skeleton equation- I2 +.docxUsing the method of 1-2 reactions balance the skeleton equation- I2 +.docx
Using the method of 1-2 reactions balance the skeleton equation- I2 +.docx
 
Using the descriptions of the attributes given in the ERD below- provi.docx
Using the descriptions of the attributes given in the ERD below- provi.docxUsing the descriptions of the attributes given in the ERD below- provi.docx
Using the descriptions of the attributes given in the ERD below- provi.docx
 
Using the following definition for a Binary Tree Node - complete the f.docx
Using the following definition for a Binary Tree Node - complete the f.docxUsing the following definition for a Binary Tree Node - complete the f.docx
Using the following definition for a Binary Tree Node - complete the f.docx
 
using the concepts of bonding and polarity explaining the importance o.docx
using the concepts of bonding and polarity explaining the importance o.docxusing the concepts of bonding and polarity explaining the importance o.docx
using the concepts of bonding and polarity explaining the importance o.docx
 
Using the competing values framework as a point of reference- how woul.docx
Using the competing values framework as a point of reference- how woul.docxUsing the competing values framework as a point of reference- how woul.docx
Using the competing values framework as a point of reference- how woul.docx
 
Using jsfiddle-net In Javascript we are going to create a doubly Linke.docx
Using jsfiddle-net In Javascript we are going to create a doubly Linke.docxUsing jsfiddle-net In Javascript we are going to create a doubly Linke.docx
Using jsfiddle-net In Javascript we are going to create a doubly Linke.docx
 
Using Haskell- I need- -- - Produce a list where sequences of repeated.docx
Using Haskell- I need- -- - Produce a list where sequences of repeated.docxUsing Haskell- I need- -- - Produce a list where sequences of repeated.docx
Using Haskell- I need- -- - Produce a list where sequences of repeated.docx
 
Using Java- Windows on the desktop are just one of many objects used i.docx
Using Java- Windows on the desktop are just one of many objects used i.docxUsing Java- Windows on the desktop are just one of many objects used i.docx
Using Java- Windows on the desktop are just one of many objects used i.docx
 
Using examples describe five major reasons for segregation of duties w.docx
Using examples describe five major reasons for segregation of duties w.docxUsing examples describe five major reasons for segregation of duties w.docx
Using examples describe five major reasons for segregation of duties w.docx
 
Using Java- Evaluate the expression- Be sure to list a value of approp.docx
Using Java- Evaluate the expression- Be sure to list a value of approp.docxUsing Java- Evaluate the expression- Be sure to list a value of approp.docx
Using Java- Evaluate the expression- Be sure to list a value of approp.docx
 
Using Java- code a dynamic Linear Quotient Hashing data structure that.docx
Using Java- code a dynamic Linear Quotient Hashing data structure that.docxUsing Java- code a dynamic Linear Quotient Hashing data structure that.docx
Using Java- code a dynamic Linear Quotient Hashing data structure that.docx
 
using C++ to Write a program to demonstrate an array of 10 elements an.docx
using C++ to Write a program to demonstrate an array of 10 elements an.docxusing C++ to Write a program to demonstrate an array of 10 elements an.docx
using C++ to Write a program to demonstrate an array of 10 elements an.docx
 
Using complete sentences- briefly answer the following- A) Accurately.docx
Using complete sentences- briefly answer the following- A) Accurately.docxUsing complete sentences- briefly answer the following- A) Accurately.docx
Using complete sentences- briefly answer the following- A) Accurately.docx
 
Using a practical example- what are the benefits and potential problem.docx
Using a practical example- what are the benefits and potential problem.docxUsing a practical example- what are the benefits and potential problem.docx
Using a practical example- what are the benefits and potential problem.docx
 
User Interface Engneering A company is designing a kiosk that can disp.docx
User Interface Engneering A company is designing a kiosk that can disp.docxUser Interface Engneering A company is designing a kiosk that can disp.docx
User Interface Engneering A company is designing a kiosk that can disp.docx
 

Recently uploaded

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Recently uploaded (20)

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 

Using C++11- Write a function that takes a char array as an input para.docx

  • 1. Using C++11: Write a function that takes a char array as an input parameter and reverses the string. The function should use two pointers, front and rear. The frontpointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the preceding character, and so on, until the entire string is reversed. Then, write a main function that takes a string as input from the user and prints the reversed string (using the above function). All input strings will be 100 characters or fewer. You must use pointers to reverse the array. If you use dynamic arrays (not required), you must delete all memory allocated to any dynamic arrays before the program ends. The program should print a string of text to the terminal before getting each line of input from the user. A session should look like one of the following examples (including whitespace and formatting), with possibly different numbers in the output: The strings printed by the program should include a newline at the end. Solution #include <iostream> #include <cstring> using namespace std; string reverse(char word[20]); int main() { char string[20]; cout<<"enter a word: "; cin>>string; string results = reverse(string);
  • 2. cout <<results; } string reverse(char word[20]) { char a='a'; char b='b'; char *front=&a; char *rear=&b; for (int i=0;i< (strlen(word)/2);i++) { front[0]=word[i]; rear[0]=word[strlen(word)-1-i]; word[i]=*rear; word[strlen(word)-1-i]=*front; } return word; }