In: Computer Science
in c++ please follow instructions and fix the errors and please make a comment next to each code error you fix.
#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;
}
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.