Each of the following declarations or code segments has errors. Locate as many as possible.
A) catch
{
quotient = divide(num1 . num2);
cout << "The quotient is " << quotient << endl;
}
try (string exceptionString)
{
cout << exceptionString;
}
B) try
{
quotient = divide(num1, num2);
}
cout << "The quotient is " << quotient « endl;
catch (string exceptionString)
{
cout << exceptionString;
}
C) template <class T>
T square(T number)
{
return T * T;
}
D) template <class T> int square(int number)
{
return number * number;
}
E) template <class T1, class T2>
T1 sum(T1 x, T1 y)
{
return x + y;
}
F) Assume the following declaration appears in a
int <SimpleVector> array(25);
G) Assume the following statement appears in a program that has defined valueSet as an object of the SimpleVector class presented in this chapter. Assume that valueSet is a
cout << valueSet<int>[2] << endl;
Want to see the full answer?
Check out a sample textbook solutionChapter 16 Solutions
Starting Out with C++: Early Objects (9th Edition)
Additional Engineering Textbook Solutions
Software Engineering (10th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Concepts of Programming Languages (11th Edition)
Concepts Of Programming Languages
Starting Out with C++ from Control Structures to Objects (8th Edition)
- Find errors / syntax error. Write line numberarrow_forward#include void main () { int a=5,b=10,c=1; if (a && b>c) { printf("cquestionbank"); } else{ break; } }arrow_forwardusing System; using System.Linq; using System.Text; namespace Games; { class Program { staticvoid Main(string[] args) { int choice,games_choice; cout<<"What are your favorite games - outdoor or indoor"<<endl; cout<<"Press 1 for 'outdoor' or Press 2 for 'indoor'"<<endl; cin>>choice; if(choice==1) { cout<<"What is your favorite outdoor game"<<endl; cout<<"Press 1 for Tennis"<<endl; cout<<"Press 2 for Football"<<endl; cout<<"Press 3 for Cricket"<<endl; cin>>games_choice; if(games_choice==1) cout<<"I also like Tennis"<<endl; elseif(games_choice==2) cout<<"I also like Football"<<endl; elseif(games_choice==3) cout<<"I also like Cricket"<<endl; } elseif(choice==2) { cout<<"What is your favorite indoor game"<<endl; cout<<"Press 1 for Ludo"<<endl; cout<<"Press 2 for Chess"<<endl; cout<<"Press 3 for Cards"<<endl;…arrow_forward
- #include using namespace std; void some_action_1(int); int main() { cout<arrow_forwardC++ Coding Help (Operators: new delete) Assign pointer myGas with a new Gas object. Call myGas's Read() to read the object's fields. Then, call myGas's Print() to output the values of the fields. Finally, delete myGas. Ex: If the input is 14 45, then the output is: Gas's volume: 14 Gas's temperature: 45 Gas with volume 14 and temperature 45 is deallocated. #include <iostream>using namespace std; class Gas { public: Gas(); void Read(); void Print(); ~Gas(); private: int volume; int temperature;};Gas::Gas() { volume = 0; temperature = 0;}void Gas::Read() { cin >> volume; cin >> temperature;} void Gas::Print() { cout << "Gas's volume: " << volume << endl; cout << "Gas's temperature: " << temperature << endl;} Gas::~Gas() { // Covered in section on Destructors. cout << "Gas with volume " << volume << " and temperature " << temperature << " is deallocated."…arrow_forward#include<stdio.h> #include<stdarg.h> void fun1(int num, ...); void fun2(int num, ...); int main() { fun1(1, "Apple", "Boys", "Cats", "Dogs"); fun2(2, 12, 13, 14); return 0; } void fun1(int num, ...) { char *str; va_list ptr; va_start(ptr, num); str = va_arg(ptr, char *); printf("%s ", str); } void fun2(int num, ...) { va_list ptr; va_start(ptr, num); num = va_arg(ptr, int); printf("%d", num); }.arrow_forward#include <iostream>#include <string>#include <climits>using namespace std; class BalancedTernary {protected:// Store the value as a reversed string of +, 0 and - charactersstring value; // Helper function to change a balanced ternary character to an integerint charToInt(char c) const {if (c == '0')return 0;return 44 - c;} // Helper function to negate a string of ternary charactersstring negate(string s) const {for (int i = 0; i < s.length(); ++i) {if (s[i] == '+')s[i] = '-';else if (s[i] == '-')s[i] = '+';}return s;} public:// Default constructorBalancedTernary() {value = "0";} // Construct from a stringBalancedTernary(string s) {value = string(s.rbegin(), s.rend());} // Construct from an integerBalancedTernary(long long n) {if (n == 0) {value = "0";return;} bool neg = n < 0;if (neg)n = -n; value = "";while (n != 0) {int r = n % 3;if (r == 0)value += "0";else if (r == 1)value += "+";else {value += "-";++n;} n /= 3;} if (neg)value = negate(value);} // Copy…arrow_forwardNonearrow_forwardNonearrow_forwardRecommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT