Display the shortest words in a sentence in JAVA
Write a method that displays all the shortest words in a given sentence. You are not allowed to use array
In the main method, ask the user to enter a sentence and call the method above to display all the shortest words in a given sentence.
You must design the algorithms for both the programmer-defined method and the main method.
In: Computer Science
Leave comments on code describing what does what
Objectives:
1. To introduce pointer variables and their relationship with arrays
2. To introduce the dereferencing operator
3. To introduce the concept of dynamic memory allocation
A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses.
The address of a variable is given by preceding the variable name with the C++ address operator (&). The & operator in front of the variable sum indicates that the address itself, and not the data stored in that location.
cout << ∑ // This outputs the address of the variable sum
To define a variable to be a pointer, we precede it with an asterisk (*). The asterisk in front of the variable indicates that ptr holds the address of a memory location.
int *ptr;
The int indicates that the memory location that ptr points to holds integer values. ptr is NOT an integer data type, but rather a pointer that holds the address of a location where an integer value is stored.
Explain the difference between the following two statements:
int sum; // ____________________________
int *sumPtr; // ___________________________
Using the symbols * and &:
The & symbol is basically used on two occasions.
reference variable : The memory address of the parameter is sent to the function instead of the value at that address.
address of a variable
void swap (int &first, int &second) // The & indicates that the parameters
{ // first and second are being passed by reference.
int temp;
temp = first; // Since first is a reference variable,
// the compiler retrieves the value
// stored there and places it in temp.
first = second // New values are written directly into
second = temp; // the memory locations of first and second.
}
2) The * symbol is used on
define pointer variables:
the contents of the memory location
int *ptr;
Experiment 1
Step 1:
Complete this program by filling in the code (places in bold). Note: use only pointer variables when instructed to by the comments in bold. This program is to test your knowledge of pointer variables and the & and * symbols.
Step 2:
Run the program with the following data: 10 15. Record the output here .
// This program demonstrates the use of pointer variables
// It finds the area of a rectangle given length and width
// It prints the length and width in ascending order
#include <iostream>
using namespace std;
int main()
{
int length; // holds length
int width; // holds width
int area; // holds area
int *lengthPtr; // int pointer which will be set to point to length
int *widthPtr; // int pointer which will be set to point to width
cout << "Please input the length of the rectangle" << endl;
cin >> length;
cout << "Please input the width of the rectangle" << endl;
cin >> width;
// Fill in code to make lengthPtr point to length (hold its address)
// Fill in code to make widthPtr point to width (hold its address)
area = // Fill in code to find the area by using only the pointer variables
cout << "The area is " << area << endl;
if (// Fill in the condition length > width by using only the pointer variables)
cout << "The length is greater than the width" << endl;
else if (// Fill in the condition of width > length by using only the pointer
// variables)
cout << "The width is greater than the length" << endl;
else
cout << "The width and length are the same" << endl;
return 0;
}
Experiment 2: Dynamic Memory
Step 1:
Complete the program by filling in the code. (Areas in bold) This problem requires that you study very carefully. The code has already written to prepare you to complete the program.
Step 2:
In inputting and outputting the name, you were asked NOT to use a bracketed subscript. Why is a bracketed subscript unnecessary? Would using name [pos] work for inputting the name? Why or why not? Would using name [pos] work for outputting the name? Why or why not?
Try them both and see.
// This program demonstrates the use of dynamic variables
#include <iostream>
using namespace std;
const int MAXNAME = 10;
int main()
{
int pos;
char * name;
int * one;
int * two;
int * three;
int result;
// Fill in code to allocate the integer variable one here
// Fill in code to allocate the integer variable two here
// Fill in code to allocate the integer variable three here
// Fill in code to allocate the character array pointed to by name
cout << "Enter your last name with exactly 10 characters." << endl;
cout << "If your name has < 10 characters, repeat last letter. " << endl
<< "Blanks at the end do not count." << endl;
for (pos = 0; pos < MAXNAME; pos++)
cin >> // Fill in code to read a character into the name array // WITHOUT USING a bracketed subscript
cout << "Hi ";
for (pos = 0; pos < MAXNAME; pos++)
cout << // Fill in code to a print a character from the name array // WITHOUT USING a bracketed subscript
cout << endl << "Enter three integer numbers separated by blanks" << endl;
// Fill in code to input three numbers and store them in the
// dynamic variables pointed to by pointers one, two, and three.
// You are working only with pointer variables
//echo print
cout << "The three numbers are " << endl;
// Fill in code to output those numbers
result = // Fill in code to calculate the sum of the three numbers
cout << "The sum of the three values is " << result << endl;
// Fill in code to deallocate one, two, three and name
return 0;
}
Sample Run:
Enter your last name with exactly 10 characters.
If your name < 10 characters, repeat last letter. Blanks do not count.
DeFinooooo
Hi DeFinooooo
Enter three integer numbers separated by blanks
5 6 7
The three numbers are 5 6 7
The sum of the three values is 18
Experiment 3: Dynamic Arrays
Question: Fill in the code as indicated by the comments in bold.
// This program demonstrates the use of dynamic arrays
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float *monthSales; // a pointer used to point to an array
// holding monthly sales
float total = 0; // total of all sales
float average; // average of monthly sales
int numOfSales; // number of sales to be processed
int count; // loop counter
cout << fixed << showpoint << setprecision(2);
cout << "How many monthly sales will be processed? ";
cin >> numOfSales;
// Fill in the code to allocate memory for the array pointed to by
// monthSales.
if ( // Fill in the condition to determine if memory has been
// allocated (or eliminate this if construct if your instructor
// tells you it is not needed for your compiler)
)
{
cout << "Error allocating memory!\n";
return 1;
}
cout << "Enter the sales below\n";
for (count = 0; count < numOfSales; count++)
{
cout << "Sales for Month number "
<< // Fill in code to show the number of the month
<< ":";
// Fill in code to bring sales into an element of the array
}
for (count = 0; count < numOfSales; count++)
{
total = total + monthSales[count];
}
average = // Fill in code to find the average
cout << "Average Monthly sale is $" << average << endl;
// Fill in the code to deallocate memory assigned to the array.
return 0;
}
Sample Run:
How many monthly sales will be processed 3
Enter the sales below
Sales for Month number 1: 401.25
Sales for Month number 2: 352.89
Sales for Month number 3: 375.05
Average Monthly sale is $376.40
In: Computer Science
You must evaluate the purchase of a proposed spectrometer for the R&D department. The base price is $300,000, and it would cost another $60,000 to modify the equipment for special use by the firm. The equipment falls into the MACRS 3-year class and would be sold after 3 years for $150,000. The applicable depreciation rates are 33%, 45%, 15%, and 7%. The equipment would require a $10,000 increase in net operating working capital (spare parts inventory). The project would have no effect on revenues, but it should save the firm $60,000 per year in before-tax labor costs. The firm's marginal federal-plus-state tax rate is 40%.
What are the project's annual cash flows in Years 1, 2, and 3? Round your answers to the nearest cent.
In Year 1 $
In Year 2 $
In Year 3 $
In: Finance
Thoroughly answer the following questions:
What is the difference between prevalence and incidence? Provide an example of each. Do not provide the definitions, explain in your own words.
In: Math
JAVA!!!!
int[][] BingoCardArray = new int[5][5];
Use a nested for-loop, to populate the 2-D array representing 5
columns for B – I – N – G – O, where
row 1 =
col 1 = random # 1-
15
col 2 = random # 16
– 30
col 3 = random # 31
– 45
col 4 = random # 46
– 60
col 5 = random # 61
– 75
row 2 =
col 1 = random # 1-
15
col 2 = random # 16
– 30
col 3 = random # 31
– 45
col 4 = random # 46
– 60
col 5 = random # 61
- 75
row 3 =
col 1 = random # 1-
15
col 2 = random # 16
– 30
col 3 = random # 31
– 45
col 4 = random # 46
– 60
col 5 = random # 61
– 75
row 4 =
col 1 = random # 1-
15
col 2 = random # 16
– 30
col 3 = random # 31
– 45
col 4 = random # 46
– 60
col 5 = random # 61
- 75
row 5 =
col 1 = random # 1-
15
col 2 = random # 16
– 30
col 3 = random # 31
– 45
col 4 = random # 46
– 60
col 5 = random # 61
– 75
The playGame()method in the BingoGame (Driver) class will loop to generate 50 random numbers in the range of 1 to 75. This simulates drawing 50 numbers in a BINGO game. The method will pass the number to a method, checkBingo()in the domain class, BingoCard, which will check if the number received as a parameter is in the B range (1 – 15), I range (16 – 30), N range (31 – 45), G range (46 -60) or O range (61 – 75). According to the range it is in, the method will check each of the cells in designated column (col 0 = B; col 1 = I; col 2 = N; col 3 = G; col 4 = O). Example: randomNum 27 was randomly generated, which belongs to the I-range, column 1, checking rows 0 to 4.
for (int row = 0; row <= 4; row++)
{
//hard-code column 1 since checking
I-column:
if (randomNum ==
BingoCardArray[row][1])
{
BingoCardArray[row][1]
= 0;
}
}
etc. //the 0 being moved to the
number simulates putting a chip on the Bingo card, marking that
the
//
number was called.
The gotBingo()method in the Bingo (Domain) class will return TRUE if 5 numbers were set to 0 either horizontally, vertically, or diagonally. Otherwise, the method will return FALSE.
Each horizontal checkis a set of if-else if statements
for (int row = 0; row < 5; row++)
{
int rowTotal = 0;
for (int col = 0; col <
5; col++)
{
//add up all the column values in that row, and see if they add up to 0.
….
}
}
Each vertical checkis a set of if-else if statements
for (int col = 0; col < 5; col++)
{
int colTotal = 0;
for (int row = 0; row <
5; row++)
{
//add up all the row values in that column, and see if they add up to 0.
….
}
}
//for diagonals check….
for (int row = 0; row < 5; row++)
{
int diagonal1Total = 0;
int diagonal2Total = 0;
for (int col = 0; col <
5; col++)
{
//figure out if it is a diagonal going one way
//figure out if it is a diagonal going the other way
….
}
}
When gotBingo()ends, it will have either returned a TRUE or a FALSE.
In the driver class, the totalGamesWon is a global variable for keeping track of how many games the user wins instead of the computer. Before the
The determineWinner()method in the Bingo (Driver) class will call the gotBIngo() method in the domain class, and if it returns true, it will add 1 to the totalGamesWon, otherwise it will leave the totalGamesWon alone.
Finally, the mainmethod will contain a do-while loop that will execute at least once, and do the following:
In: Computer Science
Define the Professional Responsibility of Practicing Engineers toward the public, the employer and the environment.
In: Civil Engineering
Write in drjava
Problem
Design and implement these 4 files:
The classes described in #1, 2 and 3 above should have the usual constructors (default and parameterized), get (accessor) and set (mutator) methods for each attribute, and a toString method
Child classes should call parent methods whenever possible to minimize code duplication.
The driver program must test all the methods in each of the classes. Include comments in your output to describe what you are testing, for example System.out.println(“testing Plant toString, accessor and mutator”);. Print out some blank lines in the output to make it easier to read and understand what is being output.
Assignment Submission:
Submit a print-out of each class file, the driver file and a sample of the output.
Marking Checklist
In: Computer Science
1) Write Java application that asks the user to enter the cost
of each apple and number of apples bought. Application obtains the
values from the user and prints the total cost of apples.
2) Write a java application that computes the cost of 135 apples,
where the cost of each apple is $0.30.
3)Write a java application that prepares the Stationery List.
Various entries in the table must be obtained from the user.
Display the Stationary list in the tabular format
In: Computer Science
A retaining wall with sloping back, of vertical height 9m retains soil of density 1.6 Mg/m3, and angle of friction 30o. The soil slopes upwards at 20o to the horizontal from the back edge of the wall, the angle between the slope and the back of the wall is 100o. Cohesion 10kN/m2, angle of friction between soil and wall is 25o but there is no cohesion between them. Find the thrust on the back wall per metre run using trial values of 25, 30, 40, and 45o for the inclination for the plane of rupture to the vertical.
In: Civil Engineering
Endocrine System Oral anti diabetic drug (Glicazide)
Instructions:
Identify the drug category
Identify both Brand name and Generic Name
Drug Action
Therapeutic effects
Dosages
Routes
Side effects
In: Nursing
Write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest)
Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2]
Do not use any special or built in functions like append, reverse etc.
In: Computer Science
Open Source Software provides a means of re-using software. All of the following are true of Open Source Software except:
A. |
The developer of the open source software does not own the code and thus cannot put restrictions on how it is used by others. |
|
B. |
Volunteers participate in the further development of the system. |
|
C. |
In an open-source development, the source code of a software system is made publicly available. |
|
D. |
Any contributor to an open source development may fix bugs and add new features to a system |
|
E. |
Open Source software can have several licensing methods such as GPL, LGPL, and BSD. |
In: Computer Science
What role does the Accounting Information System play in the production cycle by taking a Saudi Company as sample study?
Answer: It is a Critical thinking question where student has to take a Saudi company as sample study and explain the role played by AIS with regard to Production Cycle.
Accounting Information System
In: Accounting
Program using java
Take user input and give corresponding output.
A user is considering different options of operating air conditioning.
Depending on room temperature (here, room temperature is given by user), this program should give different instructions.
There are three scenarios.
- If temperature is above 90, the program should output “cooling”.
-If the temperature is below 70, the program should output “heating”.
-Otherwise, the program should output “stopped”.
For example, if user enters “95”, this is how the program should look like:
Please enter room temperature: 95
Air conditioning is cooling.
In: Computer Science
-1 -2 -3 -4 -5
-6
-11
-16
You are required to write a C program to perform two tasks.
A[i][j] = A[i-1][j]*A[i][j-1] for i > 0 and for j > 0.
After all elements in the 4x5 2-D array are fully specified, print out the content of the entire 4x5 2-D array according to the format shown below.
In: Computer Science