Questions
Draw a memory layout to show the relations of a, b and c. char a[3][10] =...

Draw a memory layout to show the relations of a, b and c.

char a[3][10] = {"abcdefg", "1234567", "!@#$%^&"};
char* b[3];
char** c;
b[0] = &a[0][0];
b[1] = &a[1][0];
b[2] = &a[2][0];
c = b;
char x = b[0][3];
char y = b[0][13];

In: Computer Science

(matlab) Since the problem is fairly complex, it may be better to complete & debug the...

(matlab) Since the problem is fairly complex, it may be better to complete & debug the program offline, then submit in Grader.

In this exercise you will complete a simplified program to play a hand of Blackjack. The goal is to complete a modular program using local and anonymous functions. Although there are several functions that must be written, they are all quite short and simple, just 1 to 4 lines. The most important learning objective is to understand how function definitions and function calls fit together.

PART 1: At the bottom of the template, complete the following local functions:

deal_hand() function

This function will generate a hand of two cards by generating two random numbers between 1 and 13.

Input argument: None

Output argument: A row vector of 2 integers between 1 and 13.

The body of the function can be implemented in a single line using the Matlab built-in function randi(). (NOTE: we are making a simplifying assumption that we have an infinite deck of cards, so we don’t have to keep track of which cards have already been dealt.)

To deal two cards, each having a value between 1 and 13, the form of the function is:

hand = randi (13, 1, 2);

display_hand() function

This function will display a blackjack hand to the screen.

input argument: a row vector containing the hand as described in 1.

output argumen: None

The contents of the display_hand() function will be as follows:

Define a row vector with characters representing the card values, like so:

cards = ['A','2','3','4','5','6','7','8','9','T','J','Q','K'];

(this can also be written more compactly as cards='A23456789TJQK')

NOTE: Each card is represented by a single character; thus ‘T’ is used for 10.

The character corresponding to a card value is accessed by indexing. For example if the card is a ten, the corresponding character using can be displayed by:

fprintf(‘%c’,cards(10))

The entire hand can be displayed with a single fprintf() call as follows:

fprintf(‘%c ’,cards(hand))

Once the hand has been displayed, print a new line using

fprintf(‘\n’)

score_hand()function

This function calculates the score of a blackjack hand.

Input argument: a hand (row vector of numbers between 1 and 13)

Output argument: the score corresponding to that hand of cards

To keep it simple, we will only allow the Ace to have a value of 1. (Allowing it to have either a value of 1 or 11 depending on context is a challenge problem that you can try after you have the rest of the game working.)

With this restriction, the value of the card is equal to the number representing the card, with the exception of face cards (11, 12, and 13), which are worth 10. You can use the min() function and the sum()function to sum the values of the cards while limiting each card to an upper value of 10.

Since the simplified score_hand() function only requires one line of code, it can be implemented via an in-line (anonymous) function. Try implementing it that way. It can be defined anywhere in the script before it is called for the first time.

deal_card() function

This function adds a card to an existing hand. Generate a single card using randi(), and use concatenation to add it to the existing hand. For example,

new_hand = [existing_hand new_card];

Input argument: a hand (row vector of numbers between 1 and 13)

Output argument: a hand consisting of the input hand with one additional card added to it.

PART 2: Add calls to your user-defined functions in the appropriate places of the template script. So that you don't have to think much about the logic of the game for this exercise, we have provided the looping and branching code.

(Script)

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

%to make an anonymous function for score_hand()

%complete this line:

score_hand = %code to calculate the score

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

%Testing the functions

testScore = score_hand(deal_card(deal_hand()));

testLength1=length(deal_hand());

testLength2=length(deal_card(deal_hand()));

disp('Blackjack:')

display_hand([1,13]);

%The main things that your program has to do are:

%

% Deal the cards

% Display the hand

% Calculate the score and store in the variable player_score or

% dealer_score

% display the score

%

%The other logic (when to quit the game, etc.) is already built into the

%template

%****************************************************

% ENTER YOUR CODE BETWEEN THE %XXXXXXXXXXXXXXX LINES.

%

%****************************************************

dealer_score = 0; %initialize dealer score so grader doesn't fail if player busts

disp('Your hand:')

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

% Deal the player's initial cards, score the hand, display the hand, display the score

player_score = 0; %Replace the 0 with a function call

fprintf('Score = %i\n', player_score);

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

hit = 1; %flag that says deal another card

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

%CHANGE THE FOLLOWING LINE AFTER YOU HAVE COMPLETED THE REST OF THE SCRIPT

%CHANGE THE 1 TO A 0

busted = 1; %flag that says player is not busted

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

while busted == 0 && hit == 1 && player_score < 21

% Since this game does not use user input, use a semi-intelligent

% algorithm to decide whether the player hits:

% if his score is <15, definitely hit

% if his score is >18, do not hit

% if his score is between 15 and 18, generate a random number

% to decide if he hits.

hit = player_score<15 || 15+randi(4)>player_score;

if hit == 1

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

% Deal one more card and calculate the score and display the hand

% and the score

fprintf('Score = %i\n', player_score); %display the score

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

if player_score > 21

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

% The player is busted and stops playing. Display a losing

% message

busted = 1;

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

end

end

end

if busted == 0

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

% Deal the dealer a separate hand, score it, then show it

disp('Dealer''s hand:')

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

while (dealer_score < player_score) && (dealer_score < 21)

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

%Deal the dealer a new card and calculate his score and display his

%new hand

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

end

if dealer_score > 21

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

% Show that the player wins

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

else

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

%Show that the dealer wins

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

end

end

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

%Complete these local functions

%Add input & output arguments as needed

function [] = deal_hand()

end

function [] = deal_card()

end

function [] = display_hand()

cards = 'A23456789TJQK';

end

%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

In: Computer Science

Write a program that will calculate the sum of the first n odd integers, and the...

Write a program that will calculate the sum of the first n odd integers, and the

sum of the first n even integers.

Use a Do while loop

Use a for loop

Here is a sample of how the program should run:

How many odd integers would you like to add? 5

Count Odd Integer Sum

1 1 1

2 3 4

3 5 9

4 7 16

5 9 25

The sum of the first 5 odd integers is 25

How many even integers would you like to add? 7

Count Even Integer Sum

1 2 2

2 4 6

3 6 12

4 8 20

5 10 30

6 12 42

7 14 56

The sum of the first 7 even integers is 56

Do you want to add again? Press y or n

y

How many odd integers would you like to add?

Make sure your program works with any input value from 1 to 1000.

REMEMBER! The sum of the first 5 odd integers is 1 + 3 + 5 + 7 + 9. It is NOT the

sum of the odd integers up to 5

In: Computer Science

Below is part of my code to sort table of x,y,z cordinates using x,y with qsort....

Below is part of my code to sort table of x,y,z cordinates using x,y with qsort. I can read all the data into *xyz part of the structure and allocate memory, I keep getting errors on line 7, "read access violation". I would take any help...Thanks

typedef struct

{

       int x;

       int y;

       int z;

} Coordinates;

typedef Coordinates * xyz;

int compare(const void *p1, const void *p2)

       {

       const xyz num1 = *(const xyz *)p1;

       const xyz num2 = *(const xyz *)p2;

7      if (num1->x < num2->x)    //read access violation

       {

              return -1;

       }

       else if (num1->x > num2->x)

       {

              return 1;

       }

       else

       {

              if (num1->y < num2->y)

              {

                     return -1;

              }

              else if (num1->y > num2->y)

              {

                     return 1;

              }

              else

              {

                     return 0;

              }

       }

Main

{

//allocates memory

Coordinates * xyz = (Coordinates *) malloc(sizeof(Coordinates) * numElem);

qsort(xyz, numElem, sizeof(xyz), compare);

}

In: Computer Science

Transfer in MIPS char * strtoupper(char s[]) { char c; c = s[0]; /* empty string...

Transfer in MIPS

char * strtoupper(char s[]) {

char c;

c = s[0];

      /* empty string */
      if (c == 0)
            return s;

/* convert the first character to upper case*/

if (c >= ‘a’ && d <= ‘z’) { c -= 32;

s[0] = c; }

/* convert the remaining characters*/

      strtoupper(s + 1);

return s; }

In: Computer Science

whats wrong here? import java.util.Scanner; public class AirportParking2 {    public static void main(String[] args) {...

whats wrong here?

import java.util.Scanner;

public class AirportParking2 {
   public static void main(String[] args) {
       Scanner scnr = new Scanner(System.in);

       int parkmins;

       System.out.print("Enter minutes parked");
       parkmins = scnr.nextInt();

       if(parkmins < 0)
           System.out.println("Invalid");
       else {
           if(parkmins > 30)
               int numbDay = parkmins/(60*24);
               parkmins -= (numbDay*24*60);

               parkfee = 24 * numbDay;

               int fee = 0;
       {
           parkmind -= 60;
           fee += 2;

           while(parkmins > 0)

           {
               fee += 1;
               parkmins -= 30;
           }  

           if(fee > 24)
               fee = 24;
       }

       parkfee += fee;
       System.out.println("Fee: $" +parkfee);


   }
}

In: Computer Science

Binary conversion: Convert 1234.5869 × 103 to IEEE 745 (show your work)

Binary conversion:

Convert 1234.5869 × 103 to IEEE 745 (show your work)

In: Computer Science

List all major steps when developing android applications. Use code examples if possible. These steps should...

List all major steps when developing android applications. Use code examples if possible. These steps should pertain to the most commonly distributed android applications. Only consider Java-based applications.

In: Computer Science

Write a single statement that prompts the user to enter their age in years and places...

Write a single statement that prompts the user to enter their age in years and places the integer value in a variable named age.

Write a short code segment in Python that prompts the user to enter the number of quarters, dimes, nickels and pennies they have, compute the total value and print that value

What convention is considered “standard” for the naming of variables and functions, in order to improve the readability of code?

What type of error will occur due to the following Python statement? -  Class = “Type II”

Using decimal scientific literal notation, write the number 314,159.

In: Computer Science

in your opinion what is Leach (2010) Can your computer make you happy in 200 words.

in your opinion what is Leach (2010) Can your computer make you happy in 200 words.

In: Computer Science

Write a C# console program that continually asks the user "Do you want to enter a...

Write a C# console program that continually asks the user "Do you want

to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters

either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and

then get keyboard input of the name. After entering the name, display the name to the screen.

---

Create a Patient class which has private fields for patientid, lastname,

firstname, age, and email. Create public data items for each of these private fields with get and

set methods. The entire lastname must be stored in uppercase. Create a main class which

instantiates a patient object and sets values for each data item within the class. Display the

data in the object to the console window.

---

Modify the Patient class with two overloaded constructors: A new default

constructor which initializes the data items for a patient object using code within the

constructor (use any data). A second constructor with parameters to pass all the data items

into the object at the time of instantiation. Create a test main class which instantiates two

objects. Instantiate the first object using the default constructor and the second object using

the constructor with the parameters.

---

Modify the main class in the patient application to include a display

method that has a parameter to pass a patient object and display its content.

---

Modify the patient class with two overloaded methods to display a bill for a

standard visit based on age. In the first method do not use any parameters to pass in data. If

the patient is over 65, then a standard visit is $75. If the patient is under 65, then the standard

doctors office visit is $125. Build a second method where you pass in a discount rate. If the

patient is over 65, then apply the discount rate to a standard rate of $125. Create a main

method that calls both of these methods and displays the results.

-----

Create two subclasses called outpatient and inpatient which inherit from

the patient base class. The outpatient class has an additional data field called doctorOfficeID

and the inpatient class has an additional data item called hospitalID. Write a main method that

creates inpatient and outpatient objects. Sets data for these objects and display the data.

---

Modify the base class of Problem 5 to be an abstract class with an abstract

display method called displayPatient that does not implement any code. Create specific

implementations for this method in both the outpatient and inpatient subclasses

In: Computer Science

In C++ with comments in code with screenshot In this assignment, you are asked to create...

In C++ with comments in code with screenshot

In this assignment, you are asked to create a class called Account, which models a bank account. The requirement of the account class is as follows, (1) It contains two data members: accountNumber and balance, which maintains the current account name and balance, respectively. (1) It contains three functions: functions credit() and debit(), which adds or subtracts the given amount from the balance, respectively. The debit() function shall print ”amount withdrawn exceeds the current balance!” if the amount is more than balance. A function print(), which shall print ”A/C no: xxx Balance=xxx” (e.g., A/C no: 991234 Balance=$88.88), with balance rounded to two decimal places.

When you submit your code, please upload your class code(s) and your test code to prove that your code works correctly.

In: Computer Science

please explain how does the following C code work. a) int function1(int num1, int num2) {...

please explain how does the following C code work.

a)

int function1(int num1, int num2) {
int num = num1 ^ num2;
int result = 0;
while(num > 0) {
result += (num & 1);
num >>= 1;
}
return result;
}

b)

int function2(unsigned int num) {
return num & ~(num - 1);
}

c)

int f1(unsigned int x) {
int count = 0;
while(x) {
count++; x = x&(x-1);
}
return count;
}

d) double ldexp(double x, int exponent) is a C math function that returns x multiplied
by 2 raised to the power of exponent. How many narrowing and how many promotions
happen automatically in the following code line? Name them one by one and explain each
one separately.
float f = 2.2f * ldexp(24.4, 3.0 * 2) - 4.4;

e)

int main() {
int a[] = {1, 2, 3, 4, 5};
int *b = a; int **c = &b;
printf("%d\n", **c*2);
printf("%d\n", **c-2*4);
printf("%d\n", **c+1-*b+1);
return 0;
}

Thanks!

In: Computer Science

Below is for C language typedef struct _node { Node *next; char *str; } Node; You...

Below is for C language

typedef struct _node {

Node *next;

char *str;

} Node;

You are given a function that takes in two Node* pointers to two different linked lists. Each linked list node has a string represented by a character array that is properly null terminated. You're function is supposed to return true if the concatenation of strings in a linked list match each other, else return false.

EXAMPLES

List 1: "h" -> "el" -> "l" -> "o" -> NULL

List 2: "he" -> "llo" -> NULL

Return: True

List 1: "je" -> "lc -> "l" -> "o" -> NULL

List 2: "h" -> "e" -> "ll" -> "" -> "o" -> NULL

Return: False

List 1: “e” -> “llo” -> “h” -> NULL

List 2: “h” -> “e” -> “l” -> “l” -> “o” -> NULL

Return: False

bool areListsMatching(Node *list1, Node *list2) {

// TODO: Fill this

}

In: Computer Science

Fill in the following table to show how the given integers are represented, assuming 16 bits...

Fill in the following table to show how the given integers are represented, assuming 16 bits are used to store values and the machine uses 2’s complement notation. (This is not necessarily MARIE.) Give values in the last two columns in hexadecimal as they would appear memory assuming the byte at address a is on the left and the byte at the address a+1 is on the right.

2-Byte Big

2-Byte Little

Integer

Binary

Hex

Endian (hex)

Endian (hex)

Example

-540

1111 1101 1110 0100

FDE4

FD E4

E4 FD

a)

12

b)

-12

c)

128

d)

-128

e)

65,000

f)

-65,000

byte a | byte a+1

byte a | byte a+1

In: Computer Science