Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Update the code to only use C++ and remove any implementation of C and implement

ID: 3602171 • Letter: U

Question

Update the code to only use C++ and remove any implementation of C and implement a cin fuction, if needed . Finally add a repeating loop into the program, that lets the user determine if they want to repeat the program

#include
#include

using namespace std;

void main()

{

    char string1[127], string2[127];

    int flag = 0;

    cout << "enter first string";

    gets(string1);

    cout << "enter second string";

    gets(string2);

    getline(string1, string2)

        for (int i = 0; i <= 120; i++)

        {

            if (string1 == wordsToFind[i] != string::quit)

            {

                ifstream the_file(argv[1]);
                if (!the_file.is_open())
                    cout << "Could not open file ";
                else {
                    char x;
                    while (the_file.get(x))
                        cout << x;
                }

            }
        }

}

Explanation / Answer

#include<iostream>

#include<string.h>

#include<stdlib.h>

using namespace std;

int main(int argc,char** argv[])

{

char string1[127], string2[127];

int flag = 0;

cout << "enter first string";

cin>>string1;

cout << "enter second string";

cin>>string2;

getline(string1,string2);

int choice;

do // i have used do while loop here so that it will execute the code atleast once
{
for (int i = 0; i <= 120; i++)

{

if (string1 == wordsToFind[i] != string::quit)

{

ifstream the_file(argv[1]);

if (!the_file.is_open())

cout << "Could not open file ";

else {

char x;

while (the_file.get(x))

cout << x;
}

}
} // till here the code will be executed once

cout<<"do you want to do it again ? Y/N "; //here i will get chance to either repeat or end the execution if i enter Y the code will be repeated otherwise execution will end.

cin>>choice;

}while(choice=='Y');
  
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote