Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Update the code below that will input three c-strings and printed those that began with yan or ended with es using loops and c-string functions.

Update the code below that will input three c-strings and printed those that began with "yan" or ended with "es" using loops and c-string functions. Modify it so string objects are used instead of c-strings. Input three strings (that could contain spaces) into an array of strings. Again use a function to first find the length for the end comparisons, then you can again compare the last two characters separately with a string function. Then use a string function to take a sub-string of the first three characters for the beginning comparison all at once. Use separate for loops to input and go through the array.

#include

#include

using namespace std; int main() { char **arr = new char*[3]; cout << "Enter 3 strings: "; for (int i = 0; i < 3; ++i) { arr[i] = new char[1000]; cin >> arr[i]; } cout << endl << "strings starting with yan and ending with es are" << endl; for (int i = 0; i < 3; ++i) { int len = strlen(arr[i]); if (strncmp(arr[i], "yan", 3) == 0 && arr[i][len - 1] == 's' && arr[i][len - 2] == 'e') { cout << arr[i] << endl; } } return 0; }

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

Step: 3

blur-text-image

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions