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 vector of 1nts and has 20 elements.
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
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Problem Solving with C++ (10th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with C++ from Control Structures to Objects (9th Edition)
SURVEY OF OPERATING SYSTEMS
Introduction To Programming Using Visual Basic (11th Edition)
- using 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_forwardWelcome Assignment ### welcome_assignment_answers ### Input - All eight questions given in the assignment. ### Output - The right answer for the specific question. def welcome_assignment_answers(question): # The student doesn't have to follow the skeleton for this assignment. # Another way to implement it is using "case" statements similar to C. if question == "Are encoding and encryption the same? - Yes/No": answer = "The student should type the answer here" elif question == "Is it possible to decrypt a message without a key? - Yes/No": answer = "The student should type the answer here" return (answer) # Complete all the questions. if __name__ == "__main__": # use this space to debug and verify that the program works debug_question = "Are encoding and encryption the same? - Yes/No" print(welcome_assignment_answers(debug_question)) As you can see, the first two questions are already in the skeleton code. Please follow the first two questions…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_forward
- 2- 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_forwardData structure & Algorithum java program Write a class name month. The class should have an int field named monthNumber that holds the number of the month. For example, January would be 1, February would be 2, etc. The class should also have appropriate constructors and getter / setter methods. There should also be a getMonthName that returns the name of the month corressponding to the month number. Also include exception code when a number less than 1 or greater than 12 is given in the constructor and/ or the set method. Demonstrate the classess and catching the exception in a program, such as Month Test. Display appropriate information to the user if an erro occurs.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_forward#include using namespace std; int main() int x=1,y=2; for (int i=0; i<3; i++) e{ x=x*y; 8{ } cout<arrow_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