Questions
Construct a permutation of the ten distinct elements (i.e. the digits 0,1,2,3,4,5,6,7,8,9) that is as bad...

Construct a permutation of the ten distinct elements (i.e. the digits 0,1,2,3,4,5,6,7,8,9) that is as bad as possible for quicksort using median-of-three partitioning. Please write out what the permutation is and describe how you found what it is.

In: Computer Science

How many iterations of the for loop does this program perform? int main(void) { int a[]...

How many iterations of the for loop does this program perform?

int main(void) {
int a[] = {1, 2, 3, 4};
int i;
for (i = 0; i < 4; i++) {
    if (a[i] < 0) return 1;
    else return 0;
}
return 0;
}

Question 1 options:

A

No iterations.

B

The program crashes.

C

One.

D

The program does not compile.

E

Four.

Question 2

What does the following program do?

int main(void) {
  int i, a[];
  a[0]=1;
  for (i=0; i<10; i++) {
    a[i] = a[i-1] + 2*i + 1;
  }
  return 0;
}

Question 2 options:

A

It crashes when it is run because no memory is reserved for the array.

B

It does not compile.

C

It fills the array with the squares of the integers from 1 to 10.

D

It fills the array with the first 10 powers of 2.

Question 3

What's the problem with this code?

int main(void) {
  int i, a[5];
  for (i=1; i <= 5; i++) {
    a[i] = i+1;
  }
  return 0;
}

Question 3 options:

A

The main problem is that the loop accesses a non-existing a[5]. This will cause some memory location to be inadvertently written. The secondary problem is that a[0] is left uninitialized.

B

It doesn't compile because one cannot declare an int variable and an int array on the same line.

C

There is no problem. The code will run just fine.

D

It crashes because a[1] is accessed before a[0].

Question 4

If a is declared with

  int a[10];

what value does sizeof(a) have?

Question 4 options:

A

14

B

Whatever is the size of a pointer to an integer.

C

10

D

10*sizeof(int)

Question 5

What does the following program do?

#include 
int main(void) {
  int a[] = {1,2,3,4};
  int b[4];  b = a;
  printf("%4d\n", b);
  return 0;
}

Question 5 options:

A

It prints 1 2 3 4.

B

The program incurs a segmentation fault when run.

C

It does not compile. You cannot copy arrays like that.

D

It does not compile. You cannot print an entire array like that.

question 6

Arrays are just pointers in disguise.

Question 6 options:

A True
B False

Question 7

Declaring too large an array in a function may cause a stack overflow when the function is called.

Question 7 options:

A True
B False

Question 8

What does the following program do?

int main(void) {
  int a[4];
  a = {1,2,3,4};
  return a[3];
}

Question 8 options:

A

It crashes because main can only return 0.

B

It returns 3.

C

It returns 4.

D

It does not compile.

Question 9

What does the following program do?

#include 

int main(void) {
  int i = 2;
  int a[] = {0,1,2,3,4};
  int n = sizeof(a) / sizeof(a[0]);
  for (i = 0; i < n; i++) {
    (*(a+i))++;
    printf(" %d", a[i]);
  }
  printf("\n");
  return 0;
}

Question 9 options:

A

It does not compile.

B

It prints: 1 1 1 1 1

C

Prints: 1 2 3 4 5.

D

It crashes because it causes a segmentation fault.

Question 10

What does the following program do?

#include 

int main(void) {
  int * p;
  int a[] = {0,1,2,3,4};
  int n = sizeof(a) / sizeof(a[0]);
  for (p = a; p != a+n; p++) {
    printf(" %d", *p);
  }
  printf("\n");
  return 0;
}

Question 10 options:

A

It crashes because p != a+n accesses an address that isout of bounds.

B

It doesn't compile. You cannot assign an array to a pointer because they are of different types.

C

It prints nonsense because %d is for integers, while p is a pointer.

D

It prints: 0 1 2 3 4

In: Computer Science

C language <stdio.h> (functions) Write a program to display a table of Fahrenheit temperatures and their...

C language <stdio.h> (functions)

Write a program to display a table of Fahrenheit temperatures and their equivalent Celsius temperatures. Create a function to do the conversion from Fahrenheit to Celsius. Invoke the function from within a for loop in main() to display the table. Ask the user for a starting temperature and and ending temperature. Validate that the starting temperature is within the range of -100 to 300 degrees, Validate that the ending temperature is in the range of -100 to 300 degrees, and is also greater than the starting temperature. Use a decision inside the ending temperature validation loop to display either the "out-of-range" message or the "greater than starting temperature" message.

The formula for converting a Fahrenheit temperature to Celsius is:
C = (5 / 9) * (F - 32)
Use this exact formula - do not pre-calculate 5/9 as .56 (you will have to type cast one of the numbers to a double for the equation to work correctly).

Format the Celsius temperatures to 1 decimal place.

Example Run #1:
(bold type is what is entered by the user)

Enter a starting Fahrenheit temperature: -200
The starting temperature must be between -100 and 300 degrees.
Please re-enter the starting temperature: 0
Enter an ending Fahrenheit temperature: 500
The ending temperature must be between -100 and 300 degrees.
Please re-enter the ending temperature: -20
The ending temperature, -20, must be greater than the starting temperature.
Please re-enter the ending temperature: 20

Fahrenheit Celsius
0 xx.x
1 xx.x
2 xx.x
3 xx.x
4 xx.x
5 xx.x
6 xx.x
7 xx.x
8 xx.x
9 xx.x
10 xx.x
11 xx.x
12 xx.x
13 xx.x
14 xx.x
15 xx.x
16 xx.x
17 xx.x
18 xx.x
19 xx.x
20 xx.x

The example run shows EXACTLY how your program input and output will look.

In: Computer Science

Create a command based menu using functions. The structure should be as followed: Under the main...

Create a command based menu using functions.

The structure should be as followed:

  • Under the main menu
    • Submenu1
    • Submenu2
    • Exit
  • SubMenu1
    • Choice1
    • Choice2
    • Back to main menu
  • Submenu2
    • Choice1
    • Choice2
    • Back to main menu
  • When I am in the submenus I want to know when I press a an option.
    • Example:
      • You have chosen choice 2 in submenu1
      • You have chosen choice 1 in submenu2
  • If an option is chosen that is incorrect I want the output to say so
    • Example:
    • "Error: you didn't choose a valid option"
  • It needs to be saved as a .PS1 file and submitted

In: Computer Science

Please convert the following machine code (given in Hex format) into assembly code and next, b)...

Please convert the following machine code (given in Hex format) into assembly code and next, b) provide the semantics of each instruction using RTL

i) 0x8FA80004

ii) 0x12110005

iii) 0x02429820

iv) ox081000A9

v) 0C0000FA

In: Computer Science

public static void main(String [] args)     {         int[] a = new int[20];         a[0]...

public static void main(String [] args)

    {

        int[] a = new int[20];

        a[0] = 0;

        a[1] = 1;

        for(int i = 2; i < 20; i++){

            a[i] = a[i - 1] + a[i - 2];

        }

        for(int i = 0; i < a.length; i++)

            System.out.println(a[i]);

    }

what would be the code when you convert this code, which is java into assembly code? Convert java into assembly code for the code above

In: Computer Science

Write a program in C++(no import of Javax or anything similar) that does the following: There...

Write a program in C++(no import of Javax or anything similar) that does the following:

There is a class human and a derived class student.
The enum in this case is gender(male, female)

Read in a text file of unknown line number that is formatted:
name;id;enum
name1;id1;enum1

The delimiter is ';'
Dynamically allocate student objects and store the objects in the array humanList (an array of human pointers). Include a counter for number of lines in the file as well.

In: Computer Science

describe how a company uses crowdsourcing to assist with its business.

describe how a company uses crowdsourcing to assist with its business.

In: Computer Science

If a heavily updated table contains many indexes, the time required to rebuild those indexes may...

If a heavily updated table contains many indexes, the time required to rebuild those indexes may degrade the overall performance of the database.

Select one:

a. True

b. False

In: Computer Science

#Write a function called clean_data. clean_data takes one #parameter, a dictionary. The dictionary represents the #observed...

#Write a function called clean_data. clean_data takes one
#parameter, a dictionary. The dictionary represents the
#observed rainfall in inches on a particular calendar day
#at a particular location. However, the data has some
#errors.
#
#clean_data should delete any key-value pair where the value
#has any of the following issues:
#
# - the type is not an integer or a float. Even if the value
# is a string that could be converted to an integer (e.g.
# "5") it should be deleted.
# - the value is less than 0: it's impossible to have a
# negative rainfall number, so this must be bad data.
# - the value is greater than 100: the world record for
# rainfall in a day was 71.8 inches
#
#Return the dictionary when you're done making your changes.
#
#Remember, the keyword del deletes items from lists
#and dictionaries. For example, to remove the key "key!" from
#the dictionary my_dict, you would write: del my_dict["key!"]
#Or, if the key was the variable my_key, you would write:
#del my_dict[my_key]
#
#Hint: If you try to delete items from the dictionary while
#looping through the dictionary, you'll run into problems!
#We should never change the number if items in a list or
#dictionary while looping through those items. Think about
#what you could do to keep track of which keys should be
#deleted so you can delete them after the loop is done.
#
#Hint 2: To check if a variable is an integer, use
#type(the_variable) == int. To check if a variable is a float,
#use type(the_variable) == float.


#Write your function here!

#Below are some lines of code that will test your function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print (although the order of the keys may vary):
#{"20190101": 5, "20190103": 7.5, "20190104": 0, "20190107": 1}
rainfall = {"20190101": 5, "20190102": "6", "20190103": 7.5,
"20190104": 0, "20190105": -7, "20190106": 102,
"20190107": 1}
print(clean_data(rainfall))

In: Computer Science

A company uses codes to represent its products, for example ABC2475A5R-14. Valid codes must have: At...

A company uses codes to represent its products, for example ABC2475A5R-14. Valid codes must have:

  • At least 10 characters (some codes have more than 10 characters)

  • Positions 4 through 7 must be digits (and represents the country in which the product will be sold)

  • The character in the 10th position must be a capital letter and represents the security level of the product.

Write a Python program that will read 10 product codes from a text file (Codes.txt - attached below). Determine if each conforms to the rules listed above:

If it does conform, print a heading: Valid Code(s) are: and list the codes that are valid. If it does not conform, print a heading: Invalid Code(s) are: and list the codes that area invalid. Be sure to test all possible combinations.

Further, if the code is valid, due to new government security laws, products with a security level of R (restricted) are no longer to be sold in countries with a country code of 2000 or higher. Output a heading: Invalid Restricted Code(s) are: and list the codes that are invalid in case you encounter any products that violate these new laws.

here is the text file data

XYZ2755R-14
RST1234A6A-12
UVW24a6R7R-13
PQR3999F85-11
STI1281J9A-04
FOR2561T4R-54
BID2075U3R-55
AGA1475P1B01
JBT2175E5X-04
KAM1145X2R-05

In: Computer Science

CRM (Customer Relationship management) What is Sentiment Analysis? What are expert systems? Tree terms Fuzzy Logic,...

CRM (Customer Relationship management)

What is Sentiment Analysis?
What are expert systems?
Tree terms Fuzzy Logic, genetic algorithms and neural networks?

In: Computer Science

C++ •Write a program that evaluates a postfix expression (assume it’s valid) such as 6 2...

C++

•Write a program that evaluates a postfix expression (assume it’s valid) such as

6 2 + 5 * 8 4 / -

•The program should read a postfix expression consisting of digits and operators into a string.

•The algorithm is as follows:

1.While you have not reached the end of the string, read the expression from left to right.

–If the current character is a digit, Push its integer value onto the stack (the integer value of a digit character is its value in the computer’s character set minus the value of '0' in the computer’s character set).

–Otherwise, if the current character is an operator, Pop the two top elements of the stack into variables x and y.

–Calculate y operator x.

Push the result of the calculation onto the stack.

2.When you reach the end of the string, pop the top value of the stack. This is the result of the postfix expression.

[Example: In Step 2 above, if the operator is '/', the top of the stack is 2 and the next element in the stack is 8, then pop 2 into x, pop 8 into y, evaluate 8 / 2 and push the result, 4, back onto the stack. This note also applies to operator '–'.]

–The arithmetic operations allowed in an expression are

+ addition

– subtraction

* multiplication

/ division

^ exponentiation

% modulus

•[Note: We assume left-to-right associativity for all operators for the purpose of this exercise.] The stack should be maintained with stack nodes that contain an int data member and a pointer to the next stack node. You may want to provide the following functional capabilities:

a.function evaluatePostfixExpression that evaluates the postfix expression

b.function calculate that evaluates the expression (op1 operator op2)

c.function push that pushes a value onto the stack

d.function pop that pops a value off the stack

e.function isEmpty that determines if the stack is empty

f.function printStack that prints the stack

SAMPLE OUTPUT:

INPUT POSTFIX NOTATION: 23+2*

INFIX NOTATION: (2+3)*2

RESULT: 10

In: Computer Science

If you could build your own personal computer, what components would you purchase? Put together a...

If you could build your own personal computer, what components would you purchase? Put together a list of the components you would use to create it, including a computer case, motherboard, CPU, hard disk, RAM, and DVD drive. How can you be sure they are all compatible with each other? How much would it cost? How does this compare to a similar computer purchased from a vendor such as Dell, HP or Apple?

Produce a Word document: outlining the components you would choose for a PC of your own design. Limit your cost to $1500. at the end write a paragraph summary explain why this would be better or worst than purchasing from Dell, HP or Apple etc.

In: Computer Science

Example of a document that misuses graphics. Discuss how the graphics are misused and what could...

Example of a document that misuses graphics. Discuss how the graphics are misused and what could be done to better them.

Please blot out any sensitive information and names

Subject: Business and Technical Report Writing

In: Computer Science