Question

In: Computer Science

in c++ please follow instructions and fix the errors and please make a comment next to...

in c++ please follow instructions and fix the errors and please make a comment next to each code error you fix.

  • Below are 25 code fragments, inserted into a try catch block.
  • Each line has zero or more errors. Your task is to find and remove all errors in each fragment.
    • Do not fix problems by simply deleting a statement; repair the problems by changing, adding, or deleting a few characters.
    • There may be different ways to fix them
    • You may need to rename variables to avoid re-declaration errors
    • When you fix a line, it should print out "Success!" and then a newline.
  • You may want to comment out each line that you have not fixed yet in order to get it to compile, so you can test as you go
  • In the end you should see a total of 25 "Success!" outputs

#include "std_lib_facilities.h"
int main()
try
{
//1.
Cout << "Success!\n";
//2.
cout << "Success!\n;
//3.
cout << "Success" << !\n"
//4.
cout << success << '\n';
//5.
string res = 7; vector<int> v(10); v[5] = res; cout << "Success!\n";
//6.
vector<int> v(10); v(5) = 7; if (v(5)!=7) cout << "Success!\n";
//7.
if (cond) cout << "Success!\n"; else cout << "Fail!\n";
//8.
bool c = false; if (c) cout << "Success!\n"; else cout << "Fail!\n";
//9.
string s = "ape"; boo c = "fool"<s; if (c) cout << "Success!\n";
//10.
string s = "ape"; if (s=="fool") cout << "Success!\n";
//11.
string s = "ape"; if (s=="fool") cout < "Success!\n";
//12.
string s = "ape"; if (s+"fool") cout < "Success!\n";
//13.
vector<char> v(5); for (int i=0; 0<v.size(); ++i) ; cout << "Success!\n";
//14.
vector<char> v(5); for (int i=0; i<=v.size(); ++i) ; cout << "Success!\n";
//15.
string s = "Success!\n"; for (int i=0; i<6; ++i) cout << s[i];
//16.
if (true) then cout << "Success!\n"; else cout << "Fail!\n";
//17.
int x = 2000; char c = x; if (c==2000) cout << "Success!\n";
//18.
string s = "Success!\n"; for (int i=0; i<10; ++i) cout << s[i];
//19.
vector v(5); for (int i=0; i<=v.size(); ++i) ; cout << "Success!\n";
//20.
int i=0; int j = 9; while (i<10) ++j; if (j<i) cout << "Success!\n";
//21.
int x = 2; double d = 5/(x–2); if (d==2*x+0.5) cout << "Success!\n";
//22.
string<char> s = "Success!\n"; for (int i=0; i<=10; ++i) cout << s[i];
//23.
int i=0; while (i<10) ++j; if (j<i) cout << "Success!\n";
//24.
int x = 4; double d = 5/(x–2); if (d=2*x+0.5) cout << "Success!\n";
//25.
cin << "Success!\n";


keep_window_open();
return 0;
}
catch (exception& e)
{
cerr << "error: " << e.what() << '\n';
keep_window_open();
return 1;
}
catch (...)
{
cerr << "Oops: unknown exception!\n";
keep_window_open();
return 2;
}

Solutions

Expert Solution

Below is the C++ code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface

#include<bits/stdc++.h>
using namespace std;
int main()
try
{
//1.
cout << "Success!\n";
//2.
cout << "Success!\n";
//3.
cout << "Success" << "!\n";
//4.
cout << "success" << "!\n";
//5.
int res = 7; vector<int> v5(10); v5[5] = res; cout << "Success!\n";
//6.
vector<int> v(10); v[5] = 7;
if (v[5]==7) cout << "Success!\n";
//7.
if (1) cout << "Success!\n"; else cout << "Fail!\n";
//8.
bool c8 = false; if (!c8) cout << "Success!\n"; else cout << "Fail!\n";
//9.
string s = "ape"; bool c9 = "fool"; if (c9) cout << "Success!\n";
//10.
string s10 = "ape"; if (s10=="ape") cout << "Success!\n";
//11.
string s11 = "ape"; if (s11=="ape") cout << "Success!\n";
//12.
string s12 = "ape"; if (s12=="ape") cout << "Success!\n";
//13.
vector<char> v13(5); for (int i=0; i<v13.size(); ++i) ; cout << "Success!\n";
//14.
vector<char> v14(5); for (int i=0; i<=v14.size(); ++i) ; cout << "Success!\n";
//15.
string s15 = "Success!\n"; for (int i=0; i<9; ++i) cout << s15[i];
//16.
if (true) cout << "Success!\n"; else cout << "Fail!\n";
//17.
int x = 2000; int c = x; if (c==2000) cout << "Success!\n";
//18.
string s18 = "Success!\n"; for (int i=0; i<9; ++i) cout << s18[i];
//19.
vector <int>v19(5); for (int i=0; i<=v19.size(); ++i) ; cout << "Success!\n";
//20.
int i=0; int j = 9;
while (i<10)
++i;
if (j<i) cout << "Success!\n";
//21.
int x21 = 2;
double d = 5/(2.0);
if (d==x21+0.5) cout << "Success!\n";
//22.
string s22 = "Success!\n"; for (int i=0; i<=8; ++i) cout << s22[i];
//23.
int i23=0,j23=10;
while (i23<10)
++i23;
if (j23<=i23) cout << "Success!\n";
//24.
int x24 = 4; double d24 = 5/(x24+2); if (d24=2*x24+0.5) cout << "Success!\n";
//25.
cout << "Success!\n";


keep_window_open();
return 0;
}
catch (exception& e)
{
cerr << "error: " << e.what() << '\n';
keep_window_open();
return 1;
}
catch (...)
{
cerr << "Oops: unknown exception!\n";
keep_window_open();
return 2;
}

I have tried to explain it in very simple language and I hope that i have answered your question satisfactorily.Leave doubts in comment section if any.


Related Solutions

Make a C program that simulates time-sharing in the operating system. Please follow the instructions provided:...
Make a C program that simulates time-sharing in the operating system. Please follow the instructions provided: a) Use a circular queue. b) It is required that the process be inputted by the user. The user must input the process name and the duration in seconds, and for this simulation let the user input 5 processes. c) As this requires process name and duration, use an array of structures. d) To simulate time-sharing, following the algorithm presented below: d.1) Use the...
Please fix all the errors in this Python program. import math def solve(a, b, c): """...
Please fix all the errors in this Python program. import math def solve(a, b, c): """ Calculate solution to quadratic equation and return @param coefficients a,b,class @return either 2 roots, 1 root, or None """ #@TODO - Fix this code to handle special cases d = b ** 2 - 4 * a * c disc = math.sqrt(d) root1 = (-b + disc) / (2 * a) root2 = (-b - disc) / (2 * a) return root1, root2 if...
Please follow the instructions and solve it by c++ Close the project and create a new...
Please follow the instructions and solve it by c++ Close the project and create a new one called 'Lab0-Part3' with the same options as in the previous step. Write a C++ program that does the following: Creates a 100-element array, either statically or dynamically Fills the array with random integers between 1 and 100 inclusive Then, creates two more 100-element arrays, one holding odd values and the other holding even values. Prints both of the new arrays to the console.
Please follow the instructions and solve it by C++. Thank you! What to Submit Submit the...
Please follow the instructions and solve it by C++. Thank you! What to Submit Submit the following: 1) Your .cpp file of the solution. 2) For what n value (approximately) does your computer stop producing output? Why is this? Enter your answer in the 'Comments' field when you submit the file.   So far in our study of recursion we identified a few common recursive number sequences, such as the Fibonacci numbers. Number sequences like this are not recursive algorithms themselves...
C++ Follow Instructions Please By placing a break in the IIF statement you are using it...
C++ Follow Instructions Please By placing a break in the IIF statement you are using it to force an exit from the WHILE loop. The break statement is only allowed with the SELECT/CASE statement. Also, don't use one structure to force an exit from another. Use the logic from the WHILE loop to end by removing the IF with the break #include <iostream> using namespace std; bool IsMultiple(int,int); int main() { char choice; int n1,n2; bool result; int test =...
q7.4 Fix the errors in the code (in C) //This program is supposed to scan 5...
q7.4 Fix the errors in the code (in C) //This program is supposed to scan 5 ints from the user //Using those 5 ints, it should construct a linked list of 5 elements //Then it prints the elements of the list using the PrintList function #include <stdio.h> struct Node{ int data; Node* next; }; int main(void){ struct Node first = {0, 0}; struct Node* second = {0, 0}; Node third = {0, 0}; struct Node fourth = {0, 0}; struct...
Please fix all of the errors in this Python Code. import math """ A collection of...
Please fix all of the errors in this Python Code. import math """ A collection of methods for dealing with triangles specified by the length of three sides (a, b, c) If the sides cannot form a triangle,then return None for the value """ ## @TODO - add the errlog method and use wolf fencing to identify the errors in this code def validate_triangle(sides): """ This method should return True if and only if the sides form a valid triangle...
q7.1 Fix the errors in the code (in C) //This program should read a string from...
q7.1 Fix the errors in the code (in C) //This program should read a string from the user and print it using a character pointer //The program is setup to use pointer offset notation to get each character of the string #include <stdio.h> #include <string.h> int main(void){ char s[1]; scanf(" %c", s); char *cPtr = s[1]; int i=0; while(1){ printf("%c", cPtr+i); i++; } printf("\n"); }
Create a C program that simulates time-sharing in the operating system. Please follow the instructions provided:...
Create a C program that simulates time-sharing in the operating system. Please follow the instructions provided: a) Use a circular queue. b) It is required that the process be inputted by the user. The user must input the process name and the duration in seconds, and for this simulation let the user input 5 processes. c) As this requires process name and duration, use an array of structures. d) To simulate time-sharing, following the algorithm presented below: d.1) Use the...
Please make it simply and easy for a beginner to follow.. -Write in C++ -Use Char...
Please make it simply and easy for a beginner to follow.. -Write in C++ -Use Char library functions -Must show that is runs Write a function that accepts a string representing password and determines whether the string is a valid password. A valid password as the following properties: 1. At least 8 characters long 2. Has at least one upper case letter 3. Has at least one lower case letter 4. Has at least one digit 5. Has at least...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT