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 (10th 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<iostream>using namespace std;void main(){double pi = 0, denominator = 1;int counter = 999999;for (int x = 0; x < counter; x++){if (x % 2 != 0){pi = pi - (1 / denominator);}else{pi = pi + (1 / denominator);}denominator = denominator + 2;}pi = pi * 4;cout << " So the computed value of a PI is = " << pi << endl;cout << " ";//return 0;system("pause");} Note: This a program called ComputePI to compute the value of π Tutor just have to Modify This program to use nested-if (if ... else if ... else if ... else) instead. Explain by applying a double line commentarrow_forward2- Trace the following code and write the output: class Test1 { Test1(int x) { System.out.println("Test Calls " + x); class Test2 { Testi t1 = new Test1(10); Test2(int i) { t1 = new Test1(i); } public static void main(String[] args) { Test2 t2 = new Test2(5);arrow_forward#include using namespace std; void some_action_1(int); int main() { cout<arrow_forwardVoid Do1 (int: &, a. int &b) { a = 5; a = a + b; b = a + 2; } Int main() { Int x = 10; Do1 (x,x); Cout << x << endl; } The output of this program isarrow_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_forwardint func(int a, int b) { return (aarrow_forwardNonearrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_iosRecommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT