What is final number output for the given code snippet

Assignment Help Programming Languages
Reference no: EM131441864

Assignment

Part 1

Question 1. A variable declared before and outside all function blocks _____.
is visible only in main
is visible to all functions
is visible to all functions except main
is not visible to any functions

Question 2. What is the final number output for the following code snippet?
for (i = 1 ; i<= 20 ; i = i + 2);
cout<< " " <<i ;
10
19
21
Illegal set-up of for loop parameters

Question 3. If firstNameand lastNameare string object variables, which statement can be used to combine (append or concatenate) the two into a single string variable?
fullName = firstName + lastName;
fullName = firstName, lastName;
fullName = firstName&lastName;
fullName = firstName&&lastName;

Question 4. C++ selection statements include _____.

for, while, and do-while
coutand cin
if, if-else, if-else if, and switch
#include <iostream> and using namespace std;

Question 5. Which of the following expressions is correct if you want to end a while loop when the character variable keepgoingis anything other than character y in either uppercase or lowercase?
while (keepgoing == "y" || keepgoing == "Y")
while (keepgoing == 'y' && keepgoing == 'Y')
while (keepgoing == "y" | | keepgoing == "Y")
while (keepgoing == 'y' | | keepgoing == 'Y')

Question 6. Given the following code fragment, what is the data type of roster[9] .name?

struct student
{
string name;
double gpa;
};
student thisStudent;
student roster[50];
string
const pointer to student
student
double

Question 7. Which type of error does the following code fragment cause?
constint MAX = 500;
int main (void)
{
int foo [MAX];
for (inti = 0; i<= MAX; i++)
{
foo [i] = i * 2;
}
Compiler, due to out-of-bounds array subscript
Run-time, due to out-of-bounds array subscript
Compiler, due to invalid array initialization
None of the above (t does not create any type of error)

Question 8. What is the data type of bullpen[3].era?
struct pitcher
{
string name;
double era;
};
pitcher p1;
pitcher bullpen[10];
string
double
pitcher
const pointer to pitcher

Question 9. What is the output of the following code?
void func(int x)
{
x = x * 2;
}
int main( )
{
int x = 10;
func(x);
cout<< x <<endl;
}
20
30
10
5

Question 10. If the function square(x) returns the square of x, then x should be passed by _____.
value so it is protected (cannot be changed)
reference so it is protected (cannot be changed)
pointer so it is protected (cannot be changed)
None of the above (x cannot be protected; square can change the value of x regardless of how it is passed)

Question 11. When a variable is passed by reference, _____.
the variable can be changed by the calling and the called function
the parameter name is an alias of the variable passed
the called function can change the value of the variable in the calling program
All of the above

Part 2

Question 1. Given the following class definition and lines of code, Line 1 in main is a call to what?
class Distance
{
private:
int feet;
double inches;
public:
Distance( );
Distance(intinitFt, double initIn);
void setFeet(intfeetIn);
void setInches(double inchesIn);
intgetFeet() const;
double getInches( ) const;
};
int main( )
{
Distance d1; //Line 1
constint MAX = 100; //Line 2
Distance list[MAX]; //Line 3
Distance d2(1, 2.3); //Line 4
Distance * pDist; //Line 5
d1.feet = 5; //Line 6
// etc. - assume the remaining code is correct
}
The 0-argument Distance constructor
The 2-argument, int, double, Distance constructor
The 2-argument, double, int, Distance constructor
The 1-argument, int, Distance constructor

Question 2. Composition is typically an example of _____.
a "has a" relationship
an "is a" relationship
a "uses a" relationship
an "is used" relationship

Question 3. Given the following class definition and lines of code, what, if anything, is wrong with Line 6 in main?
class Distance
{
private:
int feet;
double inches;
public:
Distance( );
Distance(intinitFt, double initIn);
void setFeet(intfeetIn);
void setInches(double inchesIn);
intgetFeet() const;
double getInches( ) const;
};
int main( )
{
Distance d1; //Line 1
constint MAX = 100; //Line 2
Distance list [MAX]; //Line 3
Distance d2(1, 2.3); //Line 4
Distance * pDist; //Line 5
d1.feet = 5; //Line 6
// etc. - assume the remaining code is correct
}
It will not compile because feet is private and cannot be directly accessed.
Distance d1; should be changed to int d1;.
The ::d1.feet = 5; should be changed to d1(feet) = 5;.
It will compile but will cause a run-time error because d1.feet has not been declared.

Question 4. Which of the following is called automatically each time an object is created?
Compiler
Builder
Constructor
Destructor

Question 5. Variables defined to be of a user-declared class are referred to as _____.
attributes
member variables
primitive variables
objects

Question 6. What is the data type of pDist for the code snippet below?
Distance * pDIST;
Distance
Const pointer to Distance
Pointer to Distance
None of the above

Question 7. Given the following definitions, select the statement that is illegal.
int * iptr;
double * dptr;
int j = 10;
double d = 10.0;
iptr = &j;
dptr = &d;
iptr = 0;
dptr = &j;

Question 8. Given the definition of some class called Employee, which of the following correctly dynamically allocates an array of 20 Employee objects?
Employee * myData = new Employee[20];
Employee myData[20] = new Employee[20];
Employee = myData[20];
Employee array = new Employee[20];

Question 9. In order to be able to use the JFrame, JPanel, and JButton classes, you must _____.
include the Swing header file ("Swing.h")
import the Swing class
import javax.Swing.*;
import java.awt.*;

Question 10. In the following Java code, the tfieldvariable is defined to be a JTestField. What data type must the input variable be declared as?
Input = tfield.getText( );
Double
Integer
String
String [ ]

Question 11. Which of the following creates a multiline display which is user editable?
JLabel display = new JLabel("Enter text");
JTextField display = new JTextField("Enter text");
JTextArea display = new JTextArea(20, 20);
JScrollPane display = new JScrollPane( );

Question 12. What range of numbers does the following expression generate?
Intnum = 1 + (int) (Math.Random ( ) * 100);
Minimum is 0, maximum is 100
Minimum is 1, maximum is 101
Minimum is 1, maximum is 100
Minimum is 1, maximum is 101

Question 13. What is the result of the following code?
JFrame frame = new JFrame( );
frame.add(new JButton("One"), BorderLayout.NORTH);
frame.add(new JButton("Two"), BorderLayout.NORTH);
frame.setVisible(true);
Two buttons are added side by side at the top of the display.
Button One was added first, so it is the only button at the top of the display.
Button Two was added last, so it is the only button at the top of the display.
The Java compiler will not allow you to add two buttons to the same area.

Question 14. What does the following Java code do?
JPanel pane = new JPanel( );
pane.setLayout( new gridLayout(2, 3) );
Creates a panel that will organize its components into five distinct cells
Creates a panel that displays a grid containing the numbers 2 and 3
Creates a panel that will organize its components into two rows of three columns
None of the above

Reference no: EM131441864

Questions Cloud

Why is it important to automate os installation : Why is it important to automate OS installation? How does Kanban work? How does a ticket system improve our ability to track WIP? Compare and contrast a ticket system and Kanban.
Elements that affect strategy formulation : The elements that affect strategy formulation are the same whether a company is domestic or international. Do you agree or disagree with this statement? Why? Support your argument with examples.
Calculate the expected value and volatility of the value : There are three assets A, B and C in the economy. The expected returns on assets A, B and C are 8%, 10% and 15% respectively.
Describes the nature of the problem being identified : The first submission is a short proposal of 350-500 words which describes the nature of the problem being identified; what theories, tools and techniques are available to provide a business solution; and how the various parts of the business/ orga..
What is final number output for the given code snippet : What is the final number output for following code snippet? Which of following expressions is correct if you want to end a while loop when character variable keepgoingis anything other than character y in either uppercase or lowercase?
Compute the dividends over the specific time : Suppose that a firm's recent earnings per share and dividend per share are $2.20 and $1.20, respectively. Both are expected to grow at 10 percent.
Quick-build-product-service system or complex system process : l. Diagram a process for planning and cooking a family dinner. Does your pr resemble the generic product development process? Is cooking dinner analogous to a market-pull, technology-push, platform, process-intensive, customization, high-risk, quick-..
Indifferent between going to a and b : The "Dividing Line" is the location where people are indifferent between going to A and B. That is, everyone who is located north of the line goes to stand A, and everyone south of the line goes to B.
Approaches to staffing policy-ethnocentric-polycentric : Your text describes three approaches to staffing policy: ethnocentric, polycentric, and geocentric. When is each approach appropriate? Explain your answer. Use two scholarly sources.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a program that randomly fills an array of size fifty

Write a program that randomly fills an array of size 50 with integer values from 1 to 20 inclusively. You will need to create a global constant for the size of the array; this will be used for declaring and accessing the contents of the array.

  What is programming

What is programming? Why it is so important in today environment?

  Program to find if number input by user is palindrome or not

Write down the program which uses the method called palindrome ( ) to find out if number input by user is a palindrome or not. For instance 1221 is palindrome as it can be read same way forwards and backwards.

  Implement a function for computing the achromatic phong

In this question you need to implement a function for computing the achromatic Phong illumination at a surface point.

  Write program that computes loan payments

Write a program that computes loan payments. The loan can be a car loan, a student loan, or a home mortgage loan. The program lets the user enter the interest rate.

  Program for a computer dating service

Write a program for a computer dating service. Each client gives you his or her name, phone number, and a list of interests.

  Create pseudocode for program to accept insurance data

Create a pseudocode for a program to accept insurance policy holder data, including a policy number, customer last name, customer first name, age, premium due month, day, and year,

  Program to calculate cost of purchase-requests from user

Program calculates cost of purchase, requests another item selection from user, and so on. User enters 0 from item menu to quit.

  Why do we have both debug and release builds

When two or more functions have the same name, how does the compiler determine which one to use for a particular function call?

  Write program for user to perform arithmetic operations

Write a program that lets the user perform arithmetic operations on fractions. Fractions are of the form a/b, where a and b are integers and b is not equal to 0.

  Ms word versus other processing program

MS word Versus other processing program

  Write a prolog program to solve the sudoku puzzle

Write a Prolog program to solve the 6 by 6 Sudoku puzzle distributed in class. Do not use a solution downloaded from the Internet or elsewhere. Write your own. It should be designed along these lines: Label the squares X1, X2, ..., X36 as discuss..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd