Difference between revisions of "CSC270 Final Exam 2016"

From dftwiki3
Jump to: navigation, search
Line 11: Line 11:
 
<br />
 
<br />
 
<br />
 
<br />
 +
=Problem 1=
 
<br />
 
<br />
=Problem 1=
+
::<source lang="C" highlight="40,41">
 +
#include <stdio.h>
 +
#include <stdlib.h>
 +
 
 +
int table1[] = { 1, 10, 2, 20, 5, 15, 7, 35, 11, 9 };
 +
int N1      = 10;
 +
int table2[] = { 10, 1, 20, 2, 50, 15, 35, 7, 11, 9, 22, 21 };
 +
int N2      = 12;
 +
int table3[] = { };
 +
int N3      = 0;
 +
 
 +
 
 +
typedef struct node {
 +
  int  item1;
 +
  int  item2;
 +
  struct node *next;
 +
} Node;
 +
 
 +
Node* addNode( int x, int y, Node* List ) {
 +
  Node *p = (Node *) malloc( sizeof( Node ) );
 +
  p->item1 = x;
 +
  p->item2 = y;
 +
  p->next = List;
 +
  return p;
 +
}
 +
 
 +
void display( Node* List ) {
 +
  Node *p = List;
 +
  printf( "List = " );
 +
  while (  p!= NULL ) {
 +
    printf( "(%d, %d) ", p->item1, p->item2 );
 +
    p = p->next;
 +
  }
 +
  printf( "\n\n" );
 +
}
 +
 
 +
 
 +
int main() {
 +
  Node *List = NULL;
 +
  //--- define an array (equal to table1, or table2, or table3)---
 +
  int*  table = table1;  // array
 +
  int  N    = N1;      // dimension of array
 +
 
 +
 
 +
  //--- create a linked-list of pairs of ints taken ---
 +
  //--- from table.                                ---
 +
  for ( int i=0; i<N; i += 2 )
 +
    List = addNode( table[i], table[i+1], List );
 +
 
 +
  //--- display the list ---
 +
  display( List );
 +
 
 +
  return 0;
 +
}
 +
 
 +
</source>
 +
<br />
 +
The program above creates a linked list and displays it.  The list list is composed of numbers found in an array of '''ints'''.  The program can use 3 different arrays of ints, defined at '''table1''', '''table2''', and '''table3'''.  In its implementation above, it uses table1.  If you wanted to use table2 instead, you could change the highlighted lines as illustrated below:
 +
<br />
 +
::<source lang="C">
 +
  int*  table = table1;  // array                                                                                 
 +
  int  N    = N1;      // dimension of array                                                                     
 +
</source>
 +
 
 +
<br />
 +
=Problem 2=
 
<br />
 
<br />
 
Your assignment is to connect the Arduino to the 6811 kit, and have them communicate with each other.  You should devise a design, draw it, code it, implement it, debug it, and demonstrate it.
 
Your assignment is to connect the Arduino to the 6811 kit, and have them communicate with each other.  You should devise a design, draw it, code it, implement it, debug it, and demonstrate it.

Revision as of 16:54, 19 April 2016

--D. Thiebaut (talk) 10:09, 16 April 2016 (EDT)


...