question archive Describe the model for handling graphical output and interactive input in the Abstract Windowing Toolkit (AWT) for Java
Subject:Computer SciencePrice:9.82 Bought3
Describe the model for handling graphical output and interactive input in the
Abstract Windowing Toolkit (AWT) for Java. Your answer should cover the use of
• hierarchies of classes
• overriding methods
• interfaces
In a proposed, next-generation banking system a number of transactions are to be
scheduled to run concurrently:
• Debit (D) transactions to make payments from customer accounts to a credit
card company.
• Interest (I) transactions to add daily interest to customer account balances.
• Transfer (T) transactions which first check whether the source account contains
sufficient funds then either abort or continue the transfer from source to
destination accounts. Customer x is running a T to transfer £1000 from
A to B. Customer y is running a T to transfer £200 from B to A.
(a) Discuss the potential for interference between any of these transactions.
[7 marks]
(b) Demonstrate the effect of concurrency control based on strict two-phase locking
in relation to the discussion in (a).
Annotate the uses of a given variable with 'D' (definition), 'R' (reference) and 'U'
(undefinition). Explain why three pairs of such
uses may be regarded as anomalous data flow, giving brief example programs
illustrating how each of these anomalies can represent a programmer error. Your
answer should make use of the concept of path in a dataflow graph. [3 marks]
(b) Give a single program containing all three of the above anomalies and justify it
as not containing any programmer error. [3 marks]
(c) By analogy with "on all paths" and "on some path" in dataflow analysis refine
your definition of dataflow anomaly in part (a) into that of 'must-anomaly' and
'may-anomaly' indicating which, if either, of these corresponds to the previous
definition. How many must-anomalies does your program in part (b) contain?
[3 marks]
(d) Give two sets of dataflow equations, in the style used to define "live variables"
or "available expressions", which each calculate a set of variables for every
program point. Explain how these can respectively be used to issue compiler
warning messages of the form "variable 'x' may be read before being set" and
"variable 'x' is definitely read before being set". For both forms, state the
initialisation of these sets of variables to be used when solving the dataflow
equations. [7 marks]
(e) Now suppose the language supports indirect assignment to address-taken
variables as in C. Explain briefly the refinements necessary to the above analyses.
provide answers to every question
(a) Define the terms morpheme, affix, circumfix and derivational morphology and
give examples. [4 marks]
(b) What is a finite state transducer (FST), and what is it used for in computational
linguistics? How does it differ from a finite state automaton? [3 marks]
(c) Draw an FST which recognises the affix -ly associated with regular adverbs in
English. Demonstrate that your FST correctly handles cases such as bright →
brightly, simple → simply, silly → sillily and terrific → terrifically. [9 marks]
(d) In terms of linguistic phenomena, which aspects of the morphology of adverbs
does your FST fail to handle correctly? Could these problems be fixed with a
more involved FST, or are they general problems with FST?
Sun's Network File System (NFS) is the standard distributed file system used with
UNIX, and has gone through a progression of versions (2, 3, 4) that have gradually
improved performance and semantics.
(a) Remote procedure call (RPC)
(i) Explain how Sun RPC handle byte order (endianness). [2 marks]
(ii) This approach may result in unnecessary work. State when this occurs and
how might this be avoided. [2 marks]
(b) Network File System version 2 (NFSv2) and version 3 (NFSv3)
(i) A key design premise for NFS was that the server be "stateless" with respect
to the client. State what this means for distributed file locking in NFSv2
and NFSv3.
(ii) Another key design premise for NFSv2 was the "idempotence" of RPCs;
what does this mean? [2 marks]
(iii) One key improvement in NFSv3 was the addition of the READDIRPLUS
RPC. Explain why did this helps performance. [4 marks]
(iv) NFSv3 implements what is termed "close-to-open consistency" for file data
caching: if client C1 writes to a file, closes the file, and client C2 now
opens the file for read, then it must see the results of all writes issued by
C1 prior to close. However, if C2 opens the file before C1 has closed it,
then C2 may see some, all, or none of the writes issued by C1 (and in
arbitrary order). Close-to-open consistency is achieved through careful use
of synchronous RPC semantics, combined with file timestamp information
piggybacked onto server replies on all RPCs that operate on files.
Explain how close-to-open consistency allows performance to be improved.
[4 marks]
(v) NFSv3 adds a new RPC, ACCESS, allowing the client to delegate access
control checks at file-open time to the server, rather than performing them
on the client. This allows client and server security models to differ.
8 Neural Computing (a) (i) Define generalisation in neural networks that learn from training data, and then are tested on new data. Why should not all the available data be used in the training set? [4 marks] (ii) Draw a simple connectivity diagram that illustrates the idea of lateral inhibition in a competitive neural network. [2 marks] (iii) With another diagram showing plots for input and output, illustrate how lateral inhibition in such a competitive network sharpens any input signal by effectively amplifying its first derivative. [2 marks] (iv) What class of multi-layer neural network can be used to overcome the mathematical difficulties caused by intrinsic non-orthogonality of representation in many sensory and control systems? [2 marks] (b) The study of neurological trauma to the brain gives clues about its modular organisation and specialisations of function, which may reveal some computational principles. (i) What two fundamental principles of brain function did Karl Lashley's neurological research seem to reveal? [2 marks] (ii) What are generally the differences between recovery prospects after a sudden brain trauma (in which all the damage is done at once), versus the same damage done more gradually (e.g. by a growing tumour)? [2 marks] (iii) What mechanism might explain this difference? [2 marks] (iv) Comment on its possible computational significance in terms of faulttolerance, circuit adaptability and flexibility. [2 marks] (v) Describe two different types of language-related disorders that can result from trauma to Broca's area or Wernicke's area, and comment on the computational inferences we might draw concerning language processing and linguistic representation.
: Write menu based program implementing the following functions:
(1) Write function that prompts the user for the name of a file to output as a text file that will hold two dimensional array of the long double data type
Write program to input and print the greater of three numbers.
9. Write program to input and print whether a number is positive or negative.
Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX ROWS = 10; const int MAX COLS = 10; class MatrixIype public: MatrixType0; void MakeEmpty0: void SetSize(int rowsSize, int colSize); void Storeltem(int item, int row, int col); void Add(Matrixlype otherOperand, Matrixlype& result); void Sub(Matrix Type otherOperand, MatrixIype& result; void Mult(MatrixType otherOperand, MatrixType& result); void Print(ofstream& outfile); bool AddSubCompatible(Matrixlype otherOperand); bool MultCompatible(MatrixType otherOperand); private: int values[MAX_ROWSIIMAX COLS; int numRows;
bool MultCompatible(MatrixType otherOperand); private: int values[MAX_ROWS][MAX_COLS]; int numRows; int numCols; Every instantiation of MatrixType will give you a new matrix. Initially, in the constructor, both the number of rows and the number of columns are set to 0. This indicates that an empty matrix is created. Then, the user is asked to provide the number of rows, the number of columns and the value for each combination of row and column. To represent the matrices you need to consider an array (Matrix[10) of MatrixType. Initially, the length of this array, LenthMatrix, is = 0. The index of the array can be 0 to 9, i.e., there can be at most 10 matrices at any given time. Note that the class provides two member functions, AddSubCompatible and MultCompatible, to allow the client to determine if the binary matrix operations (addition, subtraction and multiplication) are possible. For example, adding a matrix of size 3X4 with another matrix 3X7 is infeasible. You need to check such necessary preconditions for each operation. If an operation is not possible, you should provide appropriate error message to user An example of output Enter the corresponding number for your desired operation: 1- get a new matrix; 2- add two matrices; 3 - subtract a matrix from another; 4- multiply two matrices; 5- print matrix 6-end the program 1 A matrix with OX0 is created. Enter the number of rows and the number of columns:
Enter the values: 4 7 93167 5 19 100 99 3 17 Thank you. You now have total 1 matrices in system Enter the corresponding number for your desired operation: 1- get a new matrix; 2- add two matrices; 3 subtract a matrix from another; 4- multiply two matrices; 5 print matrix; 6-end the program 5 Enter the matrix number for printing: 1 The input is invalid. Enter the corresponding number for your desired operation: 1- get a new matrix; 2- add two matrices; 3 - subtract a matrix from another; 4- multiply two matrices; 5 print matrix; 6-end the program 5 Enter the matrix number for printing: 0 The matrix 0 is: 4 7 93167 5 19 100 993 17 Enter the corresponding number for your desired operation: 1- get a new matrix; 2- add two matrices; 3 - subtract a matrix from another; 4- multiply two matrices; 5- print matrix; 6-end the program 2 Let you want to perform C=A+B. Enter A, B and C: 0 1 3 The operation is not compatible. Enter the corresponding number for your desired operation: 1-get a new matrix; 2-add two matrices; 3 subtract a matrix from another; 4 multiply two matrices; 5 print matrix 6-end the program 1A matrix with 0X0 is. You now have total 2 matrices in system. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 subtract a matrix from another; 4- multiply two matrices; 5 print matrix; 6- end the program 1A matrix with OX0 is created. Enter the number of rows and the number of columns: 3 4 Enter the values: 7 19 13 6527 51 17 10 13 20 15 Thank you. You now have total 3 matrices in system. Enter the corresponding number for your desired operation: 1-get a new matrix; 2-add two matrices; 3 subtract a matrix from another; 4- multiply two matrices; 5- print matrix; 6-end the program 1 A matrix with 0XO is created. Enter the number of rows and the number of columns: 3 4 Enter the values: 17 19 13 6 53 127 10 18 103 220 5 Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5- print matrix 6- end the program 2 Let you want to perform C=A+B. Enter A, B and C: 0 2 3 Matrices 0 and 2 are added and the result is stored in matrix 3. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 add two matrices; 3 subtract a matrix from another; 4- multiply two matrices; 5 print matrix 6- end the program 5 Enter the matrix number for printing: 3 The matrix 3 is: 11 26 22 9 6 84 56 36 110 112 23 32 Enter the corresponding number for your desired operation: 1- get a new matrix; 2- add two matrices; 3- subtract a matrix from another, 4 multiply two matrices; 5-print matrix; 6-end the program 3 Let you want to perform C=A-B. Enter A, B and C:03 2 Matrix 3 is subtracted from matrix 0, and the result is stored in matrix 2. Enter the corresponding number for your desired operation: 1-get a new matrix; 2-add two matrices; 3 - subtract a matrix from another; 4- multiply two matrices; 5- print matrix; 6-end the program 4 Let you want to perform C=A*B. Enter A, B and C: 0 3 1 The operation is not compatible. Enter the corresponding number for your desired operation: 1- get a new matrix; 2- add two matrices; 3 - subtract a matrix from another; 4- multiply two matrices; 5- print matrix 6-end t Thank you. You now have total 5 matrices in system. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2- add two matrices; 3 subtract a matrix from another; 4 multiply two matrices; 5print matrix; 6-end the program 4 Let you want to perform C=A*B. Enter A, B and C:014 Matrices 0 and 1 are multiplied, and the result is stored in matrix 4.
9 Natural Language Processing The house was beautiful - Kim and Sandy especially liked the windows. They wanted to buy it, so they rang the estate agent. The preceding narrative contains several types of anaphoric relation between pronouns or definite noun phrases and discourse antecedents. Identify them. [4 marks] Describe how they might be recovered using either statistical or knowledge-based techniques. [6 marks] What are the relative advantages and disadvantages of each approach?
0 Numerical Analysis II A Riemann integral over [a, b] is defined by Z b a f(x) dx = limn0 Xn i=1 (ξi − ξi−1) f(xi) Explain the terms Riemann sum and mesh norm. [4 marks] With respect to an integral over [−1, 1] which of the following are not Riemann sums? Give explanations. (a) 0.2f(−0.9) + 0.8f(−0.1) + 0.8f(+0.1) + 0.2f(+0.9) (b) 0.8f(−0.9) + 0.2f(−0.1) + 0.2f(+0.1) + 0.8f(+0.9) (c) 0.7f(−0.6) + 0.3f(−0.4) + 0.3f(+0.4) + 0.7f(+0.6) (d) 0.5f(−0.7) + 0.8f(0) + 0.5f(+0.7) (e) 0.3f(−0.7) + 1.0f(+0.1) + 0.7f(+0.7)
Suppose R is a rule that integrates constants exactly over [−1, 1], and f(x) is bounded and Riemann-integrable over [a, b]. Write down a formula for the composite rule (n × R)f and prove that limn→∞ (n × R)f = Z b a f(x) dx [6 marks] Which of the examples (a) to (e) converge in composite form? [2 marks] Does the rule −0.5f(−1) + 1.5f(−0.4) + 1.5f(+0.4) − 0.5f(+1) converge in composite form?
#include<iostream>
#include<fstream>
#include<time.h>
using namespace std;
int main()
{
srand(time(0));
int c;
do{
cout<<"\nMenu";
cout<<"\n1. write user data into a file ";
cout<<"\n2. write random data into a file";
cout<<"\n3. read data from the file";
cout<<"\n4. perform sort by on 2d array";
cout<<"\n5. find an element in sorted 2d array";
cout<<"\n6. Quit\n";
cin>>c;
switch(c)
{
case 1:{
string file;
cout<<"\n enter the file name: ";
cin>>file;
ofstream f;
f.open(file);
int row,col;
cout<<"\n enter the row and column of the array: ";
cin>>row>>col;
f<<row<<" "<<col<<"\n";
double ar[row][col];
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
cin>>ar[i][j];
f<<ar[i][j]<<" ";
}
f<<"\n";
}
break;}
case 2:{
string file;
cout<<"\n enter the file name: ";
cin>>file;
ofstream f;
f.open(file);
int row,col;
cout<<"\n enter the row and column of the array: ";
cin>>row>>col;
f<<row<<" "<<col<<"\n";
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
double ab=rand()%100000;
double ba=rand()%100000;
if(ab<ba)
f<<ab/ba<<" ";
else
f<<ba/ab<<" ";
}
f<<"\n";
}
break;}
case 3:{
string file;
cout<<"\n enter the file name: ";
cin>>file;
ifstream f;
f.open(file);
int row,col;
f>>row>>col;
cout<<"\n data is\n";
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
double ab;
f>>ab;
cout<<ab<<" ";
}
cout<<"\n";
}
break;}
case 4:{
string file1,file2;
cout<<"\nenter the file name from which data to be taken: ";
cin>>file1;
cout<<"\n enter the file name in which sorted data to be stored: ";
cin>>file2;
ifstream f;
f.open(file1);
int row,col;
f>>row>>col;
double ar[row][col];
int i,j;
for(i=0;i<row;i++)
{
for( j=0;j<col;j++)
{
f>>ar[i][j];
}
}
int colsort;
cout<<"\nenter the column no.( starting from 0 to "<<col-1<<" )";
cin>>colsort;
for (i = 0; i < row-1; i++)
// Last i elements are already in place
for (j = 0; j < row-i-1; j++)
if (ar[j][colsort] > ar[j+1][colsort])
{
for(int k=0;k<col;k++)
{
swap(ar[j][k],ar[j+1][k]);
}
}
f.close();
ofstream ff;
ff.open(file2);
ff<<row<<" "<<col<<"\n";
for(i=0;i<row;i++)
{
for( j=0;j<col;j++)
{
ff<<ar[i][j]<<" ";
}
ff<<"\n";
}
break;}
case 5:{
string file;
cout<<"\n enter the name of the file in which data to be find: ";
cin>>file;
ifstream f;
f.open(file);
int colno;
cout<<"\n enter the column no. in which data to be find: ";
cin>>colno;
int element;
cout<<"\n enter the element to be found: ";
cin>>element;
int row,col;
f>>row>>col;
double ar[row][col];
int i,j;
for(i=0;i<row;i++)
{
for( j=0;j<col;j++)
{
f>>ar[i][j];
}
}
int l=0,r=row-1;
int flag=1;
while (l <= r) {
int m = l + (r - l) / 2;
// Check if element is present at mid
if (ar[m][colno] == element){
cout<<"\nelement found at row :"<<m;
flag=0;
}
// If element greater, ignore left half
if (ar[m][colno] < element)
l = m + 1;
// If element is smaller, ignore right half
else
r = m - 1;
}
if(flag)
cout<<"\nelement not found\n";
break;}
case 6:break;
default:{
cout<<"\nenter write choice please\n";
break;
}
}
}while(c!=6);
}
Step-by-step explanation
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter the 3 inter inputes:";
cin>>a;
cin>>b;
cin>>c;
if( a>b && a>c)
printf("A is greater");
else if(b>a and b>c)
printf("B is greater");
else
printf("C is greater");
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int a;
cout<<"Enter the number:";
cin>>a;
if( a>0)
printf("Positive");
else
printf("negative");
return 0;
}