Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HOMEWORK 10 Bitwise Operators, Enumerated Type, Miscellaneous C++ Items, and Random Number Generation 1. In either language (adjust the syntax appropriately!), compute the resulting value

HOMEWORK 10 Bitwise Operators, Enumerated Type, Miscellaneous C++ Items, and Random Number Generation

1. In either language (adjust the syntax appropriately!), compute the resulting value of z in the following statements featuring bitwise operations. Assume that the following declarations are made: int x = 24; int y = 37; . (5 points each 20 points)

a. int z = x & y;

b. int z = (y |= 77);

c. int z = y ^ x;

d. int z = x >> 4;

2. Define an enumerated type that contains these five possible values : freshman, sophomore, junior, senior, gradStudent. Then declare three variables of this type and set them equal to senior, sophomore, and junior, respectively. You may use an array. (20 points)

3. For this homework assignment, use the code this page to answer the questions on the next page. Assume that the program is run from a command prompt (in DOS, UNIX, Linux) with the file name followed by the additional arguments 37.1 and BozotheClown, OR from our online C++ compiler with 37.1 and BozotheClown entered in the Command line prompt of the lower window. (10 points each sub-part)

// Dr. Z April 30, 2007 Program I for Homework 9 (now H10) #include #include #include #include

double x = 974.23; namespace one { double x = 56.1102; } namespace two { double x = 73.8924; } using std::cout; using std::cin;

void atEnd1(void) {cout << "Bye, bye! ";} void atEnd2(void) {cout << "Bye, bye, bye! ";}

int main(int argc, char *argv[]) { atexit(atEnd1); atexit(atEnd2); double x = 11.001; short unsigned int i = 0;

cout << "This program ran with " << argc << " input arguments."; cout << std::endl << "Do you know " << argv[2] << "? "; printf("Here is the second argument: %7.2f. ",atof(argv[1])); //cout << "What will argv[1]+2 be? --> " << argv[1]+2 << " ";

cout << one::x << " " << two::x << " " << ::x << " " << x << " ";

std::vector myVals(8,1.618); for(i=0; i::iterator vIt = myVals.begin(); double weirdMax = *(std::max_element(myVals.begin(),myVals.end())); weirdMax += x; cout << "weirdMax = " << weirdMax << ". "; cout << "The size and capacity of myVals are, respectively: "; cout << myVals.size() << " and " << myVals.capacity() << ". ";

return 1; }

a. What is the output of this code?

b. What would be the complete output of the code if the following additional statements were added just before the return 1; statement? vIt += 2; printf("The value is %6.1f ",*(vIt+1));

4. Write the code to generate a sample of n normal random variables of mean and standard deviation (i.e, (N(,) random variables). Let the user select the values of n, , and , with the constraint that n 100. Then calculate the average and standard deviation of this sample and compare it (using a simple percent-error calculation) to the population values of the mean and standard deviation that were chosen by the user. You should put the basic code for generating U(0,1) random variables in a module to be imported into your program. (40 points)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions