All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Ask a Question
Search
Search
Sign In
Register
study help
computer science
introduction java program
Questions and Answers of
Introduction Java Program
Given the template of Chapter Review Question 7 and the box structure of Chapter Review Question 4, provide a template specialization that takes two box arguments and returns the one with the larger
Describe the differences between a using declaration and a using directive.
What types are assigned to v1, v2, v3, v4, and v5 in the following code (assuming the code is part of a complete program)?int g(int x);...float m = 5.5f;float & rm = m;decltype(m) v1 =
What storage scheme would you use for the following situations?a. Homer is a formal argument (parameter) to a function.b. The secret variable is to be shared by two files.c. The topsecret variable is
Here is a header file:// golf.h -- for pe9-1.cppconst int Len = 40;struct golf{char fullname[Len];int handicap;};// non-interactive version:// function sets golf structure to provided name,
Begin with the following structure declaration:struct chaff{char dross[20];int slag;};Write a program that uses placement new to place an array of two such structures in a buffer.Then assign values
Rewrite the following so that it uses using declarations instead of the using directive:#includeusing namespace std;int main(){double x;cout << "Enter value: ";while (! (cin >> x) ){cout
Write a three-file program based on the following namespace:namespace SALES{const int QUARTERS = 4;struct Sales{double sales[QUARTERS];double average;double max;double min;};// copies the lesser of 4
Suppose you want the average(3,6) function to return an int average of the two int arguments when it is called in one file, and you want it to return a double average of the two int arguments when it
What will the following two-file program display?// file1.cpp#includeusing namespace std;void other();void another();int x = 10;int y;int main(){cout << x << endl;{int x = 4;cout <<
What will the following program display?#includeusing namespace std;void other();namespace n1{int x = 1;}namespace n2{int x = 2;}int main(){using namespace n1;cout << x << endl;{int x =
Provide method definitions for the class described in Chapter Review Question 5 and write a short program that illustrates all the features.Data From Question 5Define a class to represent a bank
What is a class?
Here is a rather simple class definition:class Person {private:static const LIMIT = 25;string lname; // Person’s last namechar fname[LIMIT]; // Person’s first namepublic:Person() {lname = "";
How does a class accomplish abstraction, encapsulation, and data hiding?
Do Programming Exercise 1 from Chapter 9 but replace the code shown there with an appropriate golf class declaration. Replace setgolf(golf &, const char*, int) with a constructor with the
What is the relationship between an object and a class?
In what way, aside from being functions, are class function members different from class data members?
Define a class to represent a bank account. Data members should include the depositor’s name, the account number (use a string), and the balance. Member functions should allow the
Consider the following structure declaration:struct customer {char fullname[35];double payment;};Write a program that adds and removes customer structures from a stack, represented by a Stack class
When are class constructors called? When are class destructors called?
Here’s a class declaration:class Move{private:double x;double y;public:Move(double a = 0, double b = 0); // sets x, y to a, bshowmove() const; // shows current x, y valuesMove add(const Move &
Provide code for a constructor for the bank account class from Chapter Review Question 5.Data From Question 5Define a class to represent a bank account. Data members should include the depositor’s
A Betelgeusean plorg has these properties:DataA plorg has a name with no more than 19 letters.A plorg has a contentment index (CI), which is an integer.OperationsA new plorg starts out with a name
What is a default constructor? What is the advantage of having one?
You can describe a simple list as follows:The simple list can hold zero or more items of some particular type.You can create an empty list.You can add items to the list.You can determine whether the
Modify the Stock class definition (the version in stock20.h) so that it has member functions that return the values of the individual data members. A member that returns the company name should not
Modify the Vector class header and implementation files (Listings 11.13 and 11.14) so that the magnitude and angle are no longer stored as data components. Instead, they should be calculated on
What are this and *this?
Use a member function to overload the multiplication operator for the Stonewt class; have the operator multiply the data members by a type double value. Note that this will require carryover for the
What are the differences between a friend function and a member function?
Does a nonmember function have to be a friend to access a class’s members?
Use a friend function to overload the multiplication operator for the Stonewt class; have the operator multiply the double value by the Stone value.
Which operators cannot be overloaded?
What restriction applies to overloading the following operators? =, (), [], and ->
Define a conversion function for the Vector class that converts a Vector object to a type double value that represents the vector’s magnitude.
A complex number has two parts: a real part and an imaginary part. One way to write an imaginary number is this: (3.0, 4.0). Here 3.0 is the real part and 4.0 is the imaginary part. Suppose a =
Suppose a String class has the following private members:class String{private:char * str; // points to string allocated by newint len; // holds length of string//...};a. What’s wrong with this
Consider the following class declaration:class Cow {char name[20];char * hobby;double weight;public:Cow();Cow(const char * nm, const char * ho, double wt);Cow(const Cow c&);~Cow();Cow &
Name three problems that may arise if you define a class in which a pointer member is initialized by using new. Indicate how they can be remedied.
Enhance the String class declaration (that is, upgrade string1.h to string2.h) by doing the following:a. Overload the + operator to allow you to join two strings into one.b. Provide a stringlow()
Rewrite the Stock class, as described in Listings 10.7 and 10.8 in Chapter 10 so that it uses dynamically allocated memory directly instead of using string class objects to hold the stock names. Also
What class methods does the compiler generate automatically if you don’t provide them explicitly? Describe how these implicitly generated functions behave.
Identify and correct the errors in the following class declaration:class nifty{// datachar personality[];int talents;// methodsnifty();nifty(char * s);ostream & operator<<(ostream & os,
Consider the following class declaration:class Golfer{private:char * fullname; // points to string containing golfer's nameint games; // holds number of golf games playedint * scores; // points to
The Bank of Heather would like to know what would happen if it added a second ATM. Modify the simulation in this chapter so that it has two queues. Assume that a customer will join the first queue if
In Listing 6.2, what is the effect of replacing ++ch with ch+1?Here’s some sample output from the program in Listing 6.2:Type, and I shall repeat.An ineffable joy suffused me as I
Redo Listing 5.4 using a type array object instead of a built-in array and type long double instead of long long. Find the value of 100!Here is the output from the program in Listing 5.4:0! = 11! =
Listing 4.6 illustrates a problem created by following numeric input with line-oriented string input. How would replacing this:cin.getline(address,80);with this:cin >> address;affect the
Write a code fragment that dynamically allocates a structure of the type described in Question 8 and then reads a value for the kind member of the structure.Data From Question 8Devise a structure
Do Programming Exercise 6, but instead of declaring an array of three CandyBar structures, use new to allocate the array dynamically.Data From Exercise 6The CandyBar structure contains three members,
Declare a variable of the type defined in Question 8 and initialize it.Data From Question 8Devise a structure declaration that describes a fish.The structure should include the kind, the weight in
Do Programming Exercise 7 but use new to allocate a structure instead of declaring a structure variable. Also have the program request the pizza diameter before it requests the pizza company
Write a statement that assigns the sum of the first and last elements of the array in Question 3 to the variable even.Data From Question 3Declare an array of five ints and initialize it to the first
Rewrite Listing 4.4, using the C++ string class instead of char arrays.Here is some sample output for Listing 4.4:Enter your name:Dirk HammernoseEnter your favorite dessert:Radish TorteI have some
What are the modules of C++ programs called?
Write a C++ program that displays your name and address (or if you value your privacy, a fictitious name and address).
What does the following preprocessor directive do? #include
Write a C++ program that asks for a distance in furlongs and converts it to yards. (One furlong is 220 yards.)
What does the following statement do? using namespace std;
Write a C++ program that uses three user-defined functions (counting main() as one) and produces the following output:Three blind miceThree blind miceSee how they runSee how they runOne function,
What statement would you use to print the phrase “Hello, world” and then start a new line?
Write a program that asks the user to enter his or her age. The program then should display the age in months:Enter your age: 29Your age in months is 384.
What statement would you use to create an integer variable with the name cheeses?
Write a program that has main() call a user-defined function that takes a Celsius temperature value as an argument and then returns the equivalent Fahrenheit value. The program should request the
What statement would you use to assign the value 32 to the variable cheeses?
Write a program that has main() call a user-defined function that takes a distance in light years as an argument and then returns the distance in astronomical units. The program should request the
What statement would you use to read a value from keyboard input into the variable cheeses?
Write a program that asks the user to enter an hour value and a minute value.The main() function should then pass these two values to a type void function that displays the two values in the format
What statement would you use to print “We have X varieties of cheese,” where the current value of the cheeses variable replaces X?
What do the following function prototypes tell you about the functions?int froop(double t);void rattle(int n);int prune(void);
When do you not have to use the keyword return when you define a function?
Suppose your main() function has the following line: cout << “Please enter your PIN: “;And suppose the compiler complains that cout is an unknown identifier.What is the likely cause of this
Why does C++ have more than one integer type?
Write a short program that asks for your height in integer inches and then converts your height to feet and inches. Have the program use the underscore character to indicate where to type the
Declare variables matching the following descriptions:a. A short integer with the value 80b. An unsigned int integer with the value 42,110c. An integer with the value 3,000,000,000
Write a short program that asks for your height in feet and inches and your weight in pounds. (Use three variables to store the information.) Have the program report your body mass index (BMI).To
What safeguards does C++ provide to keep you from exceeding the limits of an integer type?
Write a program that asks the user to enter a latitude in degrees, minutes, and seconds and that then displays the latitude in decimal format.There are 60 seconds of arc to a minute and 60 minutes of
What is the distinction between 33L and 33?
Write a program that asks the user to enter the number of seconds as an integer value (use type long, or, if available, long long) and that then displays the equivalent time in days, hours, minutes,
Consider the two C++ statements that follow:char grade = 65;char grade = 'A';Are they equivalent?
Write a program that requests the user to enter the current world population and the current population of the U.S. (or of some other nation of your choice). Store the information in variables of
How could you use C++ to find out which character the code 88 represents? Come up with at least two ways.
Write a program that asks how many miles you have driven and how many gallons of gasoline you have used and then reports the miles per gallon your car has gotten. Or, if you prefer, the program can
Assigning a long value to a float can result in a rounding error.What about assigning long to double? long long to double?
Write a program that asks you to enter an automobile gasoline consumption figure in the European style (liters per 100 kilometers) and converts to the U.S. style of miles per gallon. Note that in
Evaluate the following expressions as C++ would:a. 8 * 9 + 2b. 6 * 3 / 4c. 3 / 4 * 6d. 6.0 * 3 / 4e. 15 % 4
Suppose x1 and x2 are two type double variables that you want to add as integers and assign to an integer variable. Construct a C++ statement for doing so. What if you want to add them as type double
Write a C++ program that requests and displays information as shown in the following example of output:What is your first name? Betty SueWhat is your last name? YeweWhat letter grade do you deserve?
Declare an array of five ints and initialize it to the first five odd positive integers.
Write a program that asks the user to enter his or her first name and then last name, and that then constructs, stores, and displays a third string, consisting of the user’s last name followed by a
Write a program that asks the user to enter his or her first name and then last name, and that then constructs, stores, and displays a third string consisting of the user’s last name followed by a
Write a statement that displays the value of the second element in the float array ideas.
The CandyBar structure contains three members.The first member holds the brand name of a candy bar.The second member holds the weight (which may have a fractional part) of the candy bar, and the
The CandyBar structure contains three members, as described in Programming Exercise 5.Write a program that creates an array of three CandyBar structures, initializes them to values of your choice,
What is the variable type for each of the following declarations?a. auto cars = 15;b. auto iou = 150.37f;c. auto level = 'B';d. auto crat = U'/U00002155';e. auto fract = 8.25f/2.5;
How would you declare each of the following?a. Actors is an array of 30 char.b. Betsie is an array of 100 short.c. Chuck is an array of 13 float.d. Dipsea is an array of 64 long double.
Declare an array of char and initialize it to the string "cheeseburger".
Declare a string object and initialize it to the string "Waldorf Salad".
Showing 600 - 700
of 741
1
2
3
4
5
6
7
8