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 haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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