C++
Q2.
Given the code as below. Which statement is correct?
int myAry[100];
for(int i=0; i<100; i++)
myAry = i + 2;
for(int i=100; i>0; i--)
cout << myAry[i] << '\t';
|
The first for loop assigns myAry 99 values and the null character. |
||
|
The second for loop prints out myAry elements backwards. |
||
|
The index in the second for loop is out of bounds. |
||
|
Only the first loop needs the null character. |
Q3.
A value returning function that takes one parameter, an integer. The function computes and returns the result of the following formula. The sum stops when the exponent reaches x.
21 + 22 + 23 + 24 + … + 2x
For example, if the parameter sent to the function is 4, the function will return 30, which is equal to 2 + 4 + 8 + 16.
1. (5 points) Write the function definition (header and body)
2. (2 point) Give the function prototype.
3. (2 point) Give an example of the function call (assume it is called by main but you do not need to construct the main function. )
!!! You must show the answer for each question. DO NOT attach a full program. If a full program is your answer for all these three questions, you won't earn any points.
Q4.
Write a full program, including comments!
Suppose you have a file gifts.txt that has many lines with possible Amazon gift names, gift price, and star rating.
(HERE ARE ONLY THE FIRST 4 LINES, THERE ARE MANY MORE IN THE FILE!
EchoDot 22.00 4.6
EchoShow 49.99 4.4
Fire7 29.99 3.9
KindlePaperwhite 110.00 4.3
.
.
.
The first line means that a EchoDot costs $22.00 and has 4.6 stars.
WE DO NOT KNOW HOW MANY LINES THERE ARE IN THE FILE.
Write the C++ code that (reads each line from the file and) prints out the names of all the gifts, the price and the stars.
It also prints a Y if we will buy the gift, and a M if we are not sure (maybe) if we will buy the gift. Our program has a function
that will return Y or M, depending on the price and stars. If the price is less than 30 and stars are more than 4.5 we will buy
the gift. Otherwise we will maybe buy the gift.
The program will print how many gifts we will buy, and how many we might (maybe) will buy.
So if the file was just the four lines above (OF COURSE IT HAS MORE), the output is:
Name Price Stars Buy
EchoDot 22.00 4.6 Y
EchoShow 49.99 4.4 M
Fire7 29.99 3.9 M
Kindle 110.00 4.3 M
Number of gifts we will buy: 1
Number of gifts we will maybe buy: 3
Q5. Write the definition of a void function that takes two
double parameters, say n and m. The function prints out the sum and
average of all the numbers between n and m (inclusive).
!!! Write the definition only. If your answer is a full program,
you don't earn any points.
Q6.
void bookSale(int & a, char & c, double p)
{
if ( c == 'r')
a +=4;
else
{
a *=2;
c = 'r';
}
In this function definition, which statement below is correct?
|
This function has 3 local parameters. |
||
|
A and C are reference parameters. |
||
|
a will change the actual parameter's value when this function is called. |
||
|
c can not change the actual parameter's value when this function is called because it is just a character. |
In: Computer Science
ABC Corp. is introducing a new product. The product is forecast to have $30 million per year in total fixed costs, COGS per unit is $35, and salespeople earn 5% commission on sales.
At a selling price of $100, how many units need to be sold annually to breakeven?
At the price of $100, how many units need to be sold to generate a net margin of $300,000 per year?
At the selling price of $100, how many units need to be sold annually to generate a 12% net margin?
Suppose that the annual level of total industry sales for the next year is forecast to be 2,500,000 units. If ABC is to earn a 10% net margin, what market share would they have to secure?
In: Accounting
Below are some data from the land of milk and honey
|
Year |
Price of Milk |
Quantity of Milk |
Price of Honey |
Quantity of Honey |
|
2016 |
$1 |
100 quarts |
$2 |
50 quarts |
|
2017 |
1 |
200 |
2 |
100 |
|
2018 |
2 |
200 |
4 |
100 |
In: Economics
Electro Motors (Electro) is considering a new project to produce electric vehicles for the
Australian domestic market and international markets. It has identified a property/plant that was formerly used to build petrol fuelled motor vehicles that could be refitted at minimal cost to manufacture the new electric vehicles. Electro is targeting Australian metropolitan centres for initial sales and expanding into regional centres over the next five years. International demand for electric vehicles is being driven by China and Electro has been in negotiation to provide vehicles to the Chinese market in 2025.
Electro has made the following projections:
Question 1. You have been asked to provide a further evaluation regarding the alternative use of the plant for the purpose of manufacturing electric self-driving cars, however the project life will be for 10 years. Explain how financial managers may evaluate both projects that are of unequal lives. (Only Explain theoretically with illustration whenever possible)
In: Finance
Electro Motors (Electro) is considering a new project to produce electric vehicles for the
Australian domestic market and international markets. It has identified a property/plant that was formerly used to build petrol fuelled motor vehicles that could be refitted at minimal cost to manufacture the new electric vehicles. Electro is targeting Australian metropolitan centres for initial sales and expanding into regional centres over the next five years. International demand for electric vehicles is being driven by China and Electro has been in negotiation to provide vehicles to the Chinese market in 2025.
Electro has made the following projections:
Question 1. You have been asked to provide a further evaluation regarding the alternative use of the plant for the purpose of manufacturing electric self-driving cars, however the project life will be for 10 years. Explain how financial managers may evaluate both projects that are of unequal lives. Also calculate Electro's each year's depreciation until Year 5.
In: Finance
I want to copy all the elements in f1() to f2() but in reverse order (C++)
this is my code:
#include <iostream>
#include <iomanip>
using namespace std;
const int R=10;
const int C=10;
int Array[R][C] ;
/////////////////////////////////////
void f1(){
for(int i=0 ; i<R ; i++){
for(int j=0 ; j<C ; j++){
Array[i][j]= (rand () %100) + 1;
}
}
for(int i=0 ; i<R ; i++){
for(int j=0 ; j<C ; j++){
cout<<"["<<i<<"]["<<j<<"]="<<setw(3)<<Array[i][j]<<"
";
}
cout<<endl;
}
cout<<"\n\n\n";
}
void f2(){
cout<<"////////////////////////////////////"<<endl;
cout<<"\n";
const int R2=10;
const int C2=10;
int Array[R][C];
for (int i=0 ; R<R2 ;i++){
for ( int j=0 ; C<C2 ; j++){
int swaping = Array[R][C];
Array[R][C]=Array [R2][C2];
Array [R2][C2]=swaping;
Array[R][C]++;
Array [R2][C2]--;
cout<<"["<<i<<"]["<<j<<"]="<<setw(3)<<Array[i][j]<<"
";
}
}
cout<<"\n\n";
}
int main()
{
f1();
f2();
return 0;
}
In: Computer Science
Accounting procedures allow a business to evaluate its inventory
costs based on
two methods: LIFO (Last In First Out) or FIFO (First In First Out).
A manufacturer evaluated
its finished goods inventory (in thousands) for five products with
the LIFO and FIFO methods.
To analyze the difference, they computed (FIFO - LIFO) for each
product. Based on the
following results, does the LIFO method result in a lower cost of
inventory than the FIFO
method?
| Product | FIFO | LIFO |
|---|---|---|
| 1 | 225 | 221 |
| 2 | 119 | 100 |
| 3 | 100 | 113 |
| 4 | 212 | 200 |
| 5 | 248 | 245 |
What is the decision at the 5% level of significance?
In: Statistics and Probability
The concentration of the initial stock solution is 3.00 M. The first dilution is made by measuring 10.00 mL with a volumetric pipet and diluting in a 100 mL volumetric flask. What is the concentration of the first solution?
The second solution is made by measuring 25.00 mL of the first solution and diluting in a 100 mL volumetric flask. What is the concentration of the second solution?
The third solution is made by measuring 50.00 mL of the second solution and diluting in a 250 mL volumetric flask. What is the concentration of the third solution?
The fourth solution is made by measuring 1.00 mL of the third solution and diluting in a 500 mL volumetric flask. What is the concentration of the fourth solution?
In: Chemistry
JAVA CODE
// Write a method called example that will do several things.
// It has two integer array parameters of unknown varying lengths.
// It returns an integer array that contains each of the first array values
// divided by two and each of the second array values added to the number 100.
// It prints each value of the first array and then prints that value
// divided by two on a separate line. It then prints each value of the second
// array and that value added to 100 on a separate line. It then adds the
// values of the first array and prints the sum with an appropriate label and
// adds the values of the second array and prints the sum. It then returns the
// combined array.
In: Computer Science
Suppose n unrelated families (defined as the husband, the wife, and one child) are gathered together. What is the smallest n for which chances are > 50% that there will be two or more families completely matched in birthdays (i.e., the two husbands have the same birthday, so do the two wives, and so do the two children)?
In: Statistics and Probability