Questions
Complete the code that inserts elements into a list. The list should always be in an...

Complete the code that inserts elements into a list. The list should always be in an ordered state.

#include <stdio.h>
#include <stdlib.h>

/* list of nodes, each with a single integer */
struct element {
struct element *next;
int value;
};

/* protypes for functions defined after main */
struct element *elementalloc(void);
struct element *listinitialize();
struct element *insertelement(struct element *, int);
void printlist(struct element *);

/* main
* Creates an ordered list
* Elements added to the list must be inserted maintaining the list
* in an ordered state
*/
int main() {
struct element *listhead = NULL;
listhead = listinitialize();
for (int i = 3; i < 100; i+=11){
listhead = insertnewelement(listhead, i);
}
printlist(listhead);
}

/* allocate memory for a new list element */
struct element *elementalloc(void) {
return (struct element *)malloc(sizeof(struct element));
}

/* simple list initialization function */
struct element *listinitialize() {
const int numbers[7] = {4, 9, 13, 18, 27, 49, 60};
struct element *newlist = NULL;
struct element *tail = NULL;
struct element *temp = NULL;
for (int i = 0; i < 7; i++) {
if (newlist == NULL) {
newlist = elementalloc();
newlist->next = NULL;
newlist->value = numbers[i];
tail = newlist;
} else {
temp = elementalloc();
temp->value = numbers[i];
temp->next = NULL;
tail->next = temp;
tail = tail->next;
}
}
return newlist;
}

/* function to insert elements into an ordered list */
struct element *insertnewelement(struct element *listhead, int x) {
struct element *newelement;
newelement = elementalloc();

struct element *iter = listhead;
while( ) {

}

return listhead;
}

/* print the list and the respective memory locations in list order */
void printlist(struct element *listhead)
{
while (listhead != NULL) {
printf("Memory: %p contains value: %d\n", listhead, listhead->value);
listhead = listhead->next;
}
}

In: Computer Science

Read the following specification and then answer the questions that follow. Specification: A soccer league is...

Read the following specification and then answer the questions that follow. Specification:

A soccer league is made up of at least four soccer teams. Each soccer team is composed of seven(7) to eleven(11) players, and one player captains the team. A team has a name and a record of wins and losses. Players have a number and a position. Soccer teams play games against each other. Each game has a score and a location. Teams are sometimes lead by a coach. A coach has a level of accreditation and a number of years of experience, and can coach multiple teams. Coaches and players are people, and people have names and addresses.

Question: Carry out an initial object oriented design for the above specification.

You must identify and write down. Classes that you think will be required [5 marks]

Their attributes and behaviours [2 marks]

Any inheritance relationships you can identify [3 marks]

Any other relationships (aggregation or otherwise between the classes) [2 marks]

In: Computer Science

The questions in this assessment use the following. class R { ... } class A extends...

The questions in this assessment use the following.

      class R { ... }
      class A extends R { ... }
      abstract class B extends R { ... }
      final class C extends R { ...}
      class D extends A { ... }
      class E extends B { ... }
      class F extends B { ... }
      // none of the classes implement a toString() method

[0] Draw a class hierarchy for the classes defined above.

[1] No or Yes:  class R extends Object

[2] class G extends C   does not compile. Why?

[3] class G extends E, F   does not compile. Why?

[4] B doh = new B();   does not compile. Why?

[5] System.out.println(new R());   prints: R@6bc7c054   Why?

[6] No or Yes:  class D can have subclasses (children).

[7] If  public String toString() { return "Arizona"; }  
    is added to class A, then System.out.println(new D()); 
    prints what?
[8] Assume the following is added to class C.

    public String toString() { 
       int azAgeIn2018 = 2018 - 1912;
       return "Arizona is " + azAgeIn2018 + " years young!";
    }

    What does System.out.println(new C()); print?

[9] System.out.println(new R().hashCode());  prints: 1808253012.
    No  public int hashCode()  method is implemented in class R.
    Briefly explain why this compiles and runs?

[10] If  public int hashCode() { return 48; }  is added to 
     class R, then what does the following statement print?

     System.out.println("Arizona is state# " + new R().hashCode());

In: Computer Science

Write a Fortran program which simulates placing 100 molecules into the boxes of a 20 by...

Write a Fortran program which simulates placing 100 molecules into the boxes of a 20 by 20 square grid. Each box can hold at most one molecule. Your program should count and report how many molecules in the final arrangement have no neighbors. Two molecules are considered neighbors if they are directly above or below or directly side by side (diagonals don't count). For instance, if molecules were placed at the locations labelled by letters in the following 5 by 5 grid:

       * * * * b
       a * d c *
       * * * * *
       * f * * e
       * * * * g

we would say that d and c are neighbors and e and g are neighbors, but b and c are not. In this example, the three molecules a, b, and f have no neighbors. Your program would report that 3 of the 7 molecules are isolated. Your program should perform the experiment of placing 100 molecules into an empty lattice and reporting the results five times. The results should be neatly displayed in some readable format. Your final output should not include the full picture of the lattice (although that might be useful during debugging).

This problem has many natural opportunities to use subroutines and functions. In particular, I would like your program to use a subroutine MOLPUT to place the molecules into the grid. An easy way to represent the grid is an integer array where 0 represents empty and 1 represents a molecule at that location. MOLPUT should take a single argument, which is a 20 by 20 integer array, and return with one additional molecule added to the array. This subroutine, therefore, needs to generate random subscripts until it finds an empty position in the array and then mark that a molecule has been placed there. To perform an experiment, you can then just clear the array, call MOLPUT 100 times, and then check the results.

In: Computer Science

Complete the code that inserts elements into a list. The list should always be in an...

Complete the code that inserts elements into a list. The list should always be in an ordered state.

#include <stdio.h>
#include <stdlib.h>

/* list of nodes, each with a single integer */
struct element {
struct element *next;
int value;
};

/* protypes for functions defined after main */
struct element *elementalloc(void);
struct element *listinitialize();
struct element *insertelement(struct element *, int);
void printlist(struct element *);

/* main
* Creates an ordered list
* Elements added to the list must be inserted maintaining the list
* in an ordered state
*/
int main() {
struct element *listhead = NULL;
listhead = listinitialize();
for (int i = 3; i < 100; i+=11){
listhead = insertnewelement(listhead, i);
}
printlist(listhead);
}

/* allocate memory for a new list element */
struct element *elementalloc(void) {
return (struct element *)malloc(sizeof(struct element));
}

/* simple list initialization function */
struct element *listinitialize() {
const int numbers[7] = {4, 9, 13, 18, 27, 49, 60};
struct element *newlist = NULL;
struct element *tail = NULL;
struct element *temp = NULL;
for (int i = 0; i < 7; i++) {
if (newlist == NULL) {
newlist = elementalloc();
newlist->next = NULL;
newlist->value = numbers[i];
tail = newlist;
} else {
temp = elementalloc();
temp->value = numbers[i];
temp->next = NULL;
tail->next = temp;
tail = tail->next;
}
}
return newlist;
}

/* function to insert elements into an ordered list */
struct element *insertnewelement(struct element *listhead, int x) {
struct element *newelement;
newelement = elementalloc();

struct element *iter = listhead;
while( ) {

}

return listhead;
}

/* print the list and the respective memory locations in list order */
void printlist(struct element *listhead)
{
while (listhead != NULL) {
printf("Memory: %p contains value: %d\n", listhead, listhead->value);
listhead = listhead->next;
}
}

In: Computer Science

1. Implement the recursive factorial function given below (from the lecture notes on recursion). Develop a...

1. Implement the recursive factorial function given below (from the lecture notes on recursion). Develop a main program that allows the user to enter any integer (positive) integer value, and displays the factorial of that value. The program should allow the user to either keep entering another value, or quit the program. public static int factorial(int n) { if (n == 0 || n == 1) return (1); else return (n * factorial(n-1)); } 2. Determine the largest value for n that can be correctly computed. 3. Implement the recursive Towers of Hanoi function given below (from the lecture notes). Develop a main program that allows the user to enter any number of disks to solve. public static void towers(int numDisks, String startPeg, String destPeg, String sparePeg) { if (numDisks == 1) System.out.println("Move disk from " + startPeg + " to " + destPeg); else { towers(numDisks-1, startPeg, sparePeg, destPeg); System.out.println("Move disk from " + startPeg + " to " + destPeg); towers(numDisks-1, sparePeg, destPeg, startPeg); } } 4. Modify function towers so that all the print statements are disabled (i.e., comment them out). There needs to be a statement after if(numDisks …), so replace that with just numDisks = numDisks. (The compiler will actually remove this pointless statement.) Modify the main program so that “Starting towers …” is displayed right before the function is called, and “Finished towers” when completed (right after the function call). Run your program using this new version of the function (that does not display the moves) to determine how long it takes to complete for the following number of disks: 10, 20, 30, 32, 34, 36. Use your smart phone to determine each execution time to the nearest second. use java

In: Computer Science

Write a script that finds the smallest of several nonnegative integers. Assume that the first value...

Write a script that finds the smallest of several nonnegative integers. Assume that the first value read specifies the number of values to be input from the user.

Hint: No need for Array declaration. Think like a while loop and iterate as many number as users will input. Then keep a temporary variable to keep track of the minimum.

In: Computer Science

On your own words, define different types of Computer Networks and Network Topology and discuss how...

On your own words, define different types of Computer Networks and Network Topology and discuss how it work.

In: Computer Science

Write a C program that reads an integer value. Assume it is the number of a...

Write a C program that reads an integer value. Assume it is the number of a month of the year; print out the name of that month (Hint: months need to be captured in an array).

In: Computer Science

Python Programming Exercise Scenario: Write a program that asks the user to enter scores the number...

Python Programming Exercise Scenario:

Write a program that asks the user to enter scores the number is based on what the user wants to enter. The program will display a letter grade and associated message for each score, based on the table below, and the average score. The program will not contain any repeated code and have a minimum of two functions besides Main.

Score                Letter Grade             Message

90 – 100                       A                     Excellent work

89 – 80                         B                     Nice job

79 – 70                         C                     Not bad

69 – 60                         D                     Room for improvement

Below 60                      F                      Go back and review

In: Computer Science

How would you make the shell script MyScript.sh a standalone executable (i.e. avoid to use source)?

How would you make the shell script MyScript.sh a standalone executable (i.e. avoid to use source)?

In: Computer Science

Define a problem with user input, user output, While Statement and some mathematical computation. Write the...

Define a problem with user input, user output, While Statement and some mathematical computation. Write the pseudocode, code and display output.

In: Computer Science

Develop a flowchart for ONE of the processes below and discuss the non-value added activities, bottlenecks,...

Develop a flowchart for ONE of the processes below and discuss the non-value added activities, bottlenecks, duplication or delays. Make recommendations to improve the process.

  • Registration for classes
  • Financial aid or loan application
  • Making an auto purchase
  • Making a purchase on Internet
  • Registration to a hospital
  • Organize an event or a party

In: Computer Science

Find article about (Implementing DHCP) Included with the summary must be a source notation providing the...

Find article about (Implementing DHCP)

Included with the summary must be a source notation providing the following information:

-Name of the Article

-Author

-Source information (Publication Name, URL, Article publish date)

In: Computer Science

Write a function int strlen(char s1[]) which returns the length of the char array s1.

Write a function int strlen(char s1[]) which returns the length of the char array s1.

In: Computer Science