I am asking this question again because the first expert answered my question by saying, " Step 1 I have executed the given code in online compiler as it is.  Step 2 The code is executed successfully without any warnings and error.  Sent a screenshot of the OUTPUT: ".

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I am asking this question again because the first expert answered my question by saying, "

Step 1

I have executed the given code in online compiler as it is. 

Step 2

The code is executed successfully without any warnings and error. 

Sent a screenshot of the OUTPUT: ".

 

Unfortunately, for me that response did not help me at all. I am aware that the online compiler the expert use gives no error or warning ,but I am using Visual Studio, C++ compiler for Windows 10 and I did get one warning. I am hoping an expert will see my problem and the screenshot attached and will be able to help me by fixing this code. The question I asked and screenshot is below.  I want to Thank you very much for your expert service.

 

Question and problem asked eariler 

I have a problem with the program below. Line 31 gives a warning of 3 dots (…) under the suf word suffix. I have attached a screenshot showing where the problem is and a message box stating what the problem is. If possible, can you fix this program problem please. Thank you

This is the instruction for the code below:

Write a program in C++ that reads a sentence as input and converts each word to "Pig Latin." In one version, to convert a word to Pig Latin, your remove the first letter and place the letter at the end of the word. Then you append the string "ay" to the word. Here is an example:

English:     I SLEPT MOST OF THE NIGHT

Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY

 Criteria

  • program compiles
    2) program solves problem according to specification
    3) program declares, creates, or initializes static or dynamic array correctly
    4) if required program defines function or functions with array parameters or array returns
    5) program uses arrays to solve problem
    6) program destroys any dynamic arrays

 

This is the code I am having a problem with.

#include<iostream>

#include <cstring>

#include <string>

using namespace std;

 

string piglatin(string);

string substr(string, int&);

 

int main()

{

    string input;

    cout << "Enter a sentence: ";

    getline(cin, input);

    cout << "Piglatin: " << piglatin(input) << endl << endl;

    return 0;

}

string piglatin(string input)

{

    int len = 0, counter = 0, start = 0, stop = 0;

    string word = "", newstring = "";

    do

    {

        word = substr(input, start); //translate the next word

        start++;

        newstring = newstring + word + " "; //add the word and a blank to the new sentence

    } while (start < input.length());

    return newstring;

}

string substr(string s, int& n)

{

    char word[50] = "", suffix[2];  // this is where the problem is. There's a warning of three ... under the suf

                                                        //of the word suffix[2];

    int i = 0;

    suffix[0] = s[n];    //get the first letter

    suffix[1] = '\0';

    n++;

    while (s[n] != ' ' && s[n] != '\0') //copy letters from the input to the new word until end of the word

    {

        word[i] = s[n];

        n++;

        i++;

    }

    strcat(word, suffix); //add the suffix created to the new word

    strcat(word, "ay"); //add "ay" to it

    return word;

}

Expert Answer

Step 1

I have executed the given code in online compiler as it is. 

Step 2

The code is executed successfully without any warnings and error 

Here is the OUTPUT: 

 

Homework13Problem2
| (Global Scope)
O substr(string s, int & n)
22
23
word- substr(input, start); //translate the next word
24
start++;
newstring - newstring + word + "; //add the word and a blank to the new sentence
} while (start < input.length());
return newstring;
25
26
27
28
Estring substr(string s, intå n)
30
29
char word[58] - "", suffix[2];
int i- e;
suffix[0] = s[n
suffix[1] - "le Add initializer
31
32
33
w fiect latter
34
Int1006: Local variable is not initialiced.
35
nt;
while (s[n] !-
{
word[i]
36
88 s[n] !-
end of the word
37
char word[5e] -
char word[50] -
int i- 0;
suffix[2];
suffix[2):
38
- s[n];
39
n++;
40
i+t;
41
strcat(word, suffix); //add the suffix created to the new word
strcat(word, "ay"); //add "ay" to it
return word;
42
100%
O No issues found
Ln: 31 Ch: 34 SPC
CRLF
Transcribed Image Text:Homework13Problem2 | (Global Scope) O substr(string s, int & n) 22 23 word- substr(input, start); //translate the next word 24 start++; newstring - newstring + word + "; //add the word and a blank to the new sentence } while (start < input.length()); return newstring; 25 26 27 28 Estring substr(string s, intå n) 30 29 char word[58] - "", suffix[2]; int i- e; suffix[0] = s[n suffix[1] - "le Add initializer 31 32 33 w fiect latter 34 Int1006: Local variable is not initialiced. 35 nt; while (s[n] !- { word[i] 36 88 s[n] !- end of the word 37 char word[5e] - char word[50] - int i- 0; suffix[2]; suffix[2): 38 - s[n]; 39 n++; 40 i+t; 41 strcat(word, suffix); //add the suffix created to the new word strcat(word, "ay"); //add "ay" to it return word; 42 100% O No issues found Ln: 31 Ch: 34 SPC CRLF
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Managing System
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education