Questions
The computer has important parts such as the input/output, memory and CPU. The human has similar...

The computer has important parts such as the input/output, memory and CPU. The human has similar attributes making it possible to interact with computers. As an expert in Human Computer Interaction: a. How would you model a Human as a Processor? 6 marks b. Briefly explain 4 limitations of interactive performance. 4 marks c. Use switching of a light bulb to illustrate Norman’s cycle. 9 marks d. Differentiate between error and a slip. 1 mark

In: Computer Science

Write code in Python that does the following : An anagram is when the order of...

Write code in Python that does the following : An anagram is when the order of a word can be changed to create a new word (evil,
live, and vile for example). Using the dictionary provided, find all of the anagram groups.
Which words contain the most anagrams? How large is this group? Here is another example:
Alert, alter, and later have 3 in their group. Use the provided dict.txt as your word list,
solution must also finish in less than a minute.

* I know there is no dict.txt file to use here..

file = open("dict.txt", "r", encoding="utf8")

*looking for a way to sort through the file and group anograms together

*output the groups from largest to smallest (if there is only a single word in a group, no need to display)
file.close()

In: Computer Science

What type of the combinational circuit is described by the following VHDL process? process (A,B)   ...

What type of the combinational circuit is described by the following VHDL process?
process (A,B)
   begin
   if (A = '0' and B = '1') OR (A='1' AND B='0') then
   Y <= '1';
   else
   Y <= '0';
   end if;
   end process;

1. XOR gate

2. XNOR gate

3. 2-to-1 MUX

4. half adder

In: Computer Science

DO THIS IN C#. Design and implement a program (name it MinMaxAvg) that defines three methods...

DO THIS IN C#. Design and implement a program (name it MinMaxAvg) that defines three methods as follows: Method max (int x, int y, int z) returns the maximum value of three integer values. Method min (int X, int y, int z) returns the minimum value of three integer values. Method average (int x, int y, int z) returns the average of three integer values. In the main method, test all three methods with different input value read from the user. Document your code and properly label the input prompts and the outputs as shown below. Sample run 1: You entered: 20, 8, 12 Max value: 20 Min value: 8 Average value: 13 Sample run 2: You entered: 1, 2, 3 Max value: 3 Min value: 1 Average value: 2 Sample run 3: You entered: 10, 5, 25 Max value: 25 Min value: 5 Average value: 13

In: Computer Science

3. The Hofstadter Conway sequence is defined by a(1)=a(2)=1 and (for n>2 by) a(n)=a(a(n-1))+a(n-a(n-1)). Write a...

3. The Hofstadter Conway sequence is defined by a(1)=a(2)=1 and (for n>2 by) a(n)=a(a(n-1))+a(n-a(n-1)). Write a function to quickly compute this sequence.
>>> [hc(i) for i in range(1,20)]
[1, 1, 2, 2, 3, 4, 4, 4, 5, 6, 7, 7, 8, 8, 8, 8, 9, 10, 11]

In: Computer Science

Write a function COTtupleRange(xstart,xend,xstep) that returns a tuple that has:                - as index 0 item,...

Write a function COTtupleRange(xstart,xend,xstep) that returns a tuple that has:

               - as index 0 item, the value of xstart

               - as index 1 item, the value xstart+xstep

               - as index 2 item, the value (xstart+xstep)+xstep,

               and so on as long as the value does equal or pass the value of xend.

               However, the function should return an empty string if for positive xstep, xstart>xend or if for negative xstep, xstart < xend. Here are three examples:

  • a = COTtupleRange(2, 3.51, 0.5) should produce

                  a = (2, 2.5, 3., 3.5)

  • a = COTtupleRange(2, 0.01, -0.5) should produce

                  a = (2, 1.5, 1., 0.5)

  • a = COTtupleRange(2, 1.51, 0.5) should produce

                  a = ()   

               Your code should also have a function mainProg() for testing the COTtupleRange(xstart,xend,xstep) function and the associated if __name__ == statement. Write the mainProg() code so that it does the three examples shown above.

In: Computer Science

Write a program that generates a random number between 1 and 100 and asks the user...

Write a program that generates a random number between 1 and 100 and asks the user to
guess what the number is. If the user’s guess is higher than the random number, the program
should display “Too high, try again.” If the user’s guess is lower than the random number, the
program should display “Too low, try again.” The program should use a loop that repeats until
the user correctly guesses the random number. Your program should also keep a count of the
number of guesses that the user makes. When the user correctly guesses the random number,
the program should display the number of guesses.
Style guidelines
#include directives must follow header comments, before the rest of the program.
Variable names:
--must be meaningful
--loop index names can be simple (i, j, k, etc)
--The initial letter should be lowercase, following words should be capitalized, no other caps or punctuation (ie: weightInPounds). This is called "camel case".
Named constants:
—use for most numeric literals (including array sizes). —name should be all capitals with underscores:

const double TAX_RATE = 0.0675;
—should occur near the top of the program (not inside functions).
Line length of source code should be no longer than 80 characters (no wrapping of lines).
Indentation:
--Use 2-4 spaces (but be consistent throughout your program). --Indent blocks, within blocks, etc.
--Use blank lines to separate sections.
Comments for variables:
All variable declarations should be commented as follows:
int rank; // numeric value for a card, A=1, J=11, Q=12, K=13

Comments for functions:
Function definitions should be commented to describe what it does, what the parameters are, and what the function returns (when appropriate). See the template and the example below. If the function body contains more than about five statements, there should be comments to describe the various sections of code in the function body.
Template:
//***********************************************************
// function name: short description of what the function does. //
// param-1 description of first parameter (if any)
// param-2 description of second parameter (if any)
// (remaining params, if any)
// returns: description of what function returns (if not void) //***********************************************************
Example:
//***********************************************************
// getBestPlayer: determines which player scored the most points
// p the array of player information
// size the number of players in the array
// returns the name of player who scored the most points
//***********************************************************
string getBestPlayer(Player p[], int size) {
// function body goes here
}
In-code comments:
DO NOT comment every line of code! In general, try to avoid using comments that describe WHAT the code is doing. These are redundant (we can just read the code). Comments that explain WHY the code is doing what it is doing are more helpful. Try to minimize in-code comments, and write readable code instead.
Follow these recognized good programming practices:
The grader may deduct for these issues:

1. Useappropriatedatatypes:

double populationSize; // you cannot have a fractional amount 
 // of people like 2008.55, use int


2. Avoidduplicatecode(don’tcopy,pasteandmodify):

if (monthlySales > 3000) {

cout << “Commission: $" << price * 0.25 << endl;

}

else {

cout << “Commission: $" << price * 0.29 << endl;
 }

better:

double rate;

if (monthlySales > 3000) {
 rate = 0.25;

}

else {

rate = 0.29;
cout << “Commission: $" << price * rate << endl;
3. Donotuseuninitializedvariables:

int total; //should be initialized to 0;
 for (..;..;..)

total = total + x; //on first use, total has garbage in it

4. Useanamedconstantforanarraysize:

const int SIZE = 100; //NOT: int SIZE;
 . . .

double myArray[SIZE];

5. Avoidoutofboundsarrayaccess:
 for example:

for (int i=0; i<=SIZE; i++) { // when i == SIZE it goes 

// beyond the end of the array

. . . myArray[i] . . .
 }

6. Donotuseglobalvariables(butglobalnamedconstantsaregood).

7. Usereferenceparametersonlywhennecessary.

In: Computer Science

Of the primary areas of US concern surrounding cybersecurity, what do you think is the most...

Of the primary areas of US concern surrounding cybersecurity, what do you think is the most important issue facing policy makers?

In: Computer Science

The following code must be written using matlab How to get the elements that are different...

The following code must be written using matlab

How to get the elements that are different in two set without using the setdiff function in matlbab?

In: Computer Science

I need the following C code converted to java or C++ #include <stdio.h> #include <stdlib.h> typedef...

I need the following C code converted to java or C++

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

typedef struct node {
struct node *left;
struct node *right;
long data;

long leftSize;
} node;

void btreeInsert(node *new, node **rootptr) {
node *parent = NULL, *cursor;
/* Find parent */
cursor = *rootptr;
while (cursor != NULL) {
parent = cursor;
if (new->data < cursor->data) {
cursor->leftSize += 1;
cursor = cursor->left;
} else {
cursor = cursor->right;
}
}
/* Insert node below parent */
if (parent == NULL) {
*rootptr = new;
} else if (new->data < parent->data) {
parent->left = new;
} else {
parent->right = new;
}
}

node *readTree(FILE *dataFile) {
node *root = NULL, *new;
long element;
while (fscanf(dataFile, "%ld\n", &element) == 1) {
new = malloc(sizeof(node));
new->data = element;
new->right = NULL;
new->left = NULL;
new->leftSize = 0;
btreeInsert(new, &root);
}
return root;
}

long kthOrder(int k, node *root) {
node *current;
current = root;
while (k != current->leftSize + 1) {
if (k <= current->leftSize) {
current = current->left;
} else {
k -= current->leftSize + 1;
current = current->right;
}
}
return current->data;
}

void reportKthOrderStats(FILE *positionFile, node *root) {
int position;
while (fscanf(positionFile, "%i\n", &position) == 1) {
printf("%ld\n", kthOrder(position, root));
}
}

int main(int argc, const char * argv[]) {
const char *data, *range;
FILE *dataFile, *rangeFile;
node *root;

data = argv[1];
range = argv[2];
dataFile = fopen(data, "r");
rangeFile = fopen(range, "r");

root = readTree(dataFile);
reportKthOrderStats(rangeFile, root);

return (0);
}

In: Computer Science

In this unit, you learned about some of the benefits of web-based applications. What are some...

  1. In this unit, you learned about some of the benefits of web-based applications. What are some potential disadvantages?
  2. Consider this URL: https://www.nasa.gov/topics/humans-in-space. What does each part of it mean?
  3. Can you imagine a system that might be used that would help people to recognize whether information found online is more reliable or less reliable?
  4. Imagine that you wanted to do a web search on hotels, but not motels or condos, in New England. What could you add to your search so that you would get the most relevant results?
  5. You are trying to clean your apartment when your vacuum cleaner stops working. What online reference tools might be useful to you?

In: Computer Science

Write a program in NASM that turns a 32-bit numeric value (e.g., 0xFFFFh) and converts it...

Write a program in NASM that turns a 32-bit numeric value (e.g., 0xFFFFh) and converts it to a byte array such that it can be printed to the screen using a system call method. A loop is necessary for converting the numeric value to ASCII for output. Again, use a system call (e.g., int 80h) to print the value to the console. Calling external functions (e.g. printf) is not allowed. You may use the starter file attached to this assignment.

In: Computer Science

Program Description Write and test a MASM program to perform the following tasks: Display your name...

Program Description

Write and test a MASM program to perform the following tasks:

  1. Display your name and program title on the output screen.
  2. Display instructions for the user.
  3. Prompt the user to enter three numbers (A, B, C) in descending order.
  4. Calculate and display the sum and differences: (A+B, A-B, A+C, A-C, B+C, B-C, A+B+C).
  5. Display a closing message.

Program Requirements

  1. The program must be fully documented and laid out according to the CS271 Style Guide. This includes a complete header block for identification, description, etc., and a comment outline to explain each section of code.
  2. The main procedure must be divided into logical sections:
    1. introduction
    2. get the data
    3. calculate the required values
    4. display the results
    5. say goodbye
  3. The results of calculations must be stored in named variables before being displayed.

In: Computer Science

Write the code in Java: 1. Create a method that displays your name in the console....

Write the code in Java:

1. Create a method that displays your name in the console. This method is void and takes no parameters. Make an app that runs the method in response to a button press.

2. Create a version of the method in #1 that takes the text (String) to be displayed as a parameter. Allow the user to enter the text in a dialog box or text field and display that text in the console. Be sure to trim() the text.

In: Computer Science

c++ "Programming For Big Data [ DvcScheduleV2.cpp and StaticArray.h and/or DynamicArray.h ] Assignment 5's runtime was...

c++ "Programming For Big Data [ DvcScheduleV2.cpp and StaticArray.h and/or DynamicArray.h ]
Assignment 5's runtime was too slow -- a couple of minutes or so. It's because of the duplicate-checking, with over 4 billion compares.

Rewrite the duplicate-checking logic from Assignment 5, using a technique from "Techniques For Big Data, Reading" to do fewer compares, and come up with the exact same results as Assignment 5.

You may use your StaticArray.h from Assignment 3 and/or your DynamicArray.h from assignments 4, but you may not use any STL containers. Submit the H file(s) you use in your solution, even if there are no changes since your previous work. Your project will be compiled for grading using the default stack memory size of 1MB.

Progress Bar

Since this version is supposed to be fast, there is no longer a need for a progress bar. Include one if you wish, or you may leave it out -- your choice. But if you do have a progress bar, do remember to "flush"...

You should get the same result as V1 and should run an order of magnitude faster."

For some reason I'm getting different results from my first version of the programs and the program I've written for this assignment.

Code for the prior assignment :

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

#include <cstring>
#include "DynamicArray.h"

struct Class
{
string code;
int count;
};

int main()
{

DynamicArray <Class> sub;
DynamicArray <string> sem;
DynamicArray <string> sec;

int totalSubjects = 0;
int dup = 0;
int total = 0;
int counter = 0;
bool duplicate;
bool stored;

//for parsing inputfile
char* token;
char buf[1000];
const char* const tab = "\t";

//open input file
ifstream fin;
fin.open("dvc-schedule.txt");
if (!fin.good())
cout << "I/O error. File can't be found!\n";

//read the input file
while (fin.good())
{
//progress bar
if(counter % 1000 == 0)
cout << '.'; cout.flush();
duplicate = false;
stored = false;
string line;
getline(fin, line);
total++; //total lines processed
strcpy(buf, line.c_str());
if (buf[0] == 0) continue; // skip blank lines
//parse the line
const string term(token = strtok(buf, tab));
const string section(token = strtok(0, tab));
const string course((token = strtok(0, tab)) ? token : "");
const string instructor((token = strtok(0, tab)) ? token : "");
const string whenWhere((token = strtok(0, tab)) ? token : "");
if (course.find('-') == string::npos) continue;
const string code(course.begin(), course.begin() + course.find('-'));

//check for duplicates
for(int i = 0; i < counter; i++)
{
if(sem[i] == term && sec[i] == section)
{
dup++;
duplicate = true;
break;
}
}

if(duplicate == true)
continue;

sem[counter] = term;
sec[counter] = section;
counter++;

for(int i = 0; i < totalSubjects; i++)
{
if (sub[i].code == code)
{
sub[i].count++;
stored = true;
break;
}
}

if(stored == true)
continue;

Class y;
y.code = code;
y.count = 1;
sub[totalSubjects] = y;
totalSubjects++;
}
fin.close();
cout << endl;

//sort
for (int i = 0; i < totalSubjects; i++)
for (int j = i + 1; j < totalSubjects; j++)
if (sub[j].code < sub[i].code)
swap(sub[j], sub[i]);

//output
for(int i = 0; i < totalSubjects; i++)
{
cout << sub[i].code << ", " << sub[i].count << " section" << endl;
}
cout << "Total duplication: " << dup << endl;
cout << "Total counts: " << total << endl;
cout << "Total subjects: " << totalSubjects << endl;
}

Code for this assignment:

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

#include <cstring>
#include "DynamicArray.h"

struct SectionsForTerm
{
string term;
int numberOfSectionsSeen;
DynamicArray<string> seenSectionNumbers;
};

struct Class
{
string code;
int count;
};

int main()
{

int numberOfTermsSeen = 0;
DynamicArray <SectionsForTerm> alreadySeen;
DynamicArray <Class> sub;

int totalSubjects = 0;
int dup = 0;
int total = 0;
int counter = 0;
bool match;
bool duplicate;
bool stored;

//for parsing inputfile
char* token;
char buf[1000];
const char* const tab = "\t";

//open input file
ifstream fin;
fin.open("dvc-schedule.txt");
if (!fin.good())
cout << "I/O error. File can't be found!\n";

//read the input file
while (fin.good())
{
//check for false
match = false;
duplicate = false;
stored = false;

//read lines
string line;
getline(fin, line);
total++; //total lines processed
strcpy(buf, line.c_str());
if (buf[0] == 0) continue; // skip blank lines

//parse the line
const string term(token = strtok(buf, tab));
const string section(token = strtok(0, tab));
const string course((token = strtok(0, tab)) ? token : "");
const string instructor((token = strtok(0, tab)) ? token : "");
const string whenWhere((token = strtok(0, tab)) ? token : "");
if (course.find('-') == string::npos) continue;
const string code(course.begin(), course.begin() + course.find('-'));

//check for duplicates
int i;
for(int i = 0; i < numberOfTermsSeen; i++)
{
if(alreadySeen[i].term == term)
{
match = true;
break;
}
}

if(match == true)
{
for(int j = 0; j < alreadySeen[i].numberOfSectionsSeen; j++)
if (alreadySeen[i].seenSectionNumbers[j]== section)
{
duplicate = true;
dup++;
break;
}

if (duplicate == true)
continue;

else
{
alreadySeen[i].seenSectionNumbers[alreadySeen[i].numberOfSectionsSeen]= section;
alreadySeen[i].numberOfSectionsSeen++;
}
}

else
{
alreadySeen[numberOfTermsSeen].term = term;
alreadySeen[i].numberOfSectionsSeen = 1;
numberOfTermsSeen++;
}

// check for same section
for(i = 0; i < totalSubjects; i++)
{
if(sub[i].code == code)
{
stored = true;
break;
}
}

if(stored == true)
{
sub[i].count++;
}

else
{
sub[totalSubjects].code = code;
sub[totalSubjects].count = 1;
totalSubjects++;
}

counter++;
}
fin.close();
cout << endl;

//sort
for (int i = 0; i < totalSubjects; i++)
for (int j = i + 1; j < totalSubjects; j++)
if (sub[j].code < sub[i].code)
swap(sub[j], sub[i]);

//output
for(int i = 0; i < totalSubjects; i++)
{
cout << sub[i].code << ", " << sub[i].count << " section" << endl;
}
cout << "Total duplication: " << dup << endl;
cout << "Total counts: " << total << endl;
cout << "Total subjects: " << totalSubjects << endl;
}

*When I compare the results of both programs the subjects and total are the same but the total duplication number is significantly off. Also the amount of sections per course is off? I'm not really sure how, why, or how to fix it?

In: Computer Science