Questions
Instructions Write a program in C++ that create a LookupNames project. In the main function: Ask...

Instructions

Write a program in C++ that create a LookupNames project.

In the main function:
Ask the user to enter a number of names, X to quit input.
Store the names in an array.
Also use a counter variable to count the number of names entered.

Write a function displayNames to display the names.
The function must receive the array and the counter as parameters.

Write a function called lookupNames.
The function must receive the array and the counter as parameters.
Ask the user to enter a letter.
Display all the names with the letter that was entered as the first letter of the name.

Call the displayNames and lookupNames functions from the main function.


Tip: declare your functions above the main() function:

void displayNames(char array[][60], int count)
{
// function code here
}

int main()
{
// main code here
displayNames(names, number);
// possible more code here
}

Tip2: make sure your function parameter matches the data type you send as an argument to that function.
In the above example, names and array should have the same data type, and number and count should have the same data type.


Enter name (X to quit input): John Peterson
Enter name (X to quit input): Diane Lee
Enter name (X to quit input): James Smith
Enter name (X to quit input): Frank Xaba
Enter name (X to quit input): Jacky Mokabe
Enter name (X to quit input): x


List of Names

John Peterson
Diane Lee
James Smith
Frank Xaba
Jacky Mokabe

Enter a letter: J

Names starting with the letter J

John Peterson
James Smith
Jacky Mokabe

In: Computer Science

Assignment #1: Sorting with Binary Search Tree Through this programming assignment, the students will learn to...

Assignment #1: Sorting with Binary Search Tree Through this programming assignment, the students will learn to do the following: 1. Know how to process command line arguments. 2. Perform basic file I/O. 3. Use structs, pointers, and strings. 4. Use dynamic memory. This assignment asks you to sort the lines of an input file (or from standard input) and print the sorted lines to an output file (or standard output). Your program, called bstsort (binary search tree sort), will take the following command line arguments: % bstsort [-c] [-o output_file_name] [input_file_name] If -c is present, the program needs to compare the strings case sensitive; otherwise, it's case insensitive. If the output_file_name is given with the -o option, the program will output the sorted lines to the given output file; otherwise, the output shall be the standard output. Similarly, if the input_file_name is given, the program will read from the input file; otherwise, the input will be from the standard input. You must use getopt() to parse the command line arguments to determine the cases. All strings will be no more than 100 characters long. In addition to parsing and processing the command line arguments, your program needs to do the following: 1. You need to construct a binary search tree as you read from input. A binary search tree is a binary tree. Each node can have at most two child nodes (one on the left and one on the right), both or either one can be empty. If a child node exists, it's the root of a binary search tree (we call subtree). Each node contains a key (in our case, it's a string) and a count of how many of that string were included. If he left subtree of a node exists, it contains only nodes with keys less than the node's key. If the right subtree of a node exists, it contains only nodes with keys greater than the node's key. You can look up binary search tree on the web or in your Data Structure textbook. Note that you do not need to balance the binary search tree (that is, you can ignore all those rotation operations) in this assignment. 2. Initially the tree is empty (that is, the root is null). The program reads from the input file (or stdin) one line at a time; If the line is not an empty line and the line is not already in the tree, it should create a tree node that stores a pointer to the string and a count of 1 indicating this is the first occurrence of that string, and then insert the tree node to the binary search tree. An empty line would indicate the end of input for stdin, an empty line or end of file would indicate the end of input for an input file. If the line is not an empty line and the line is already in the tree, increase the count for that node indicating that there are multiple instances of that line. 3. You must develop two string comparison functions, one for case sensitive and the other for case insensitive. You must not use the strcmp() and strcasecmp() functions provided by the C library. You must implement your own version. You will be comparing the ASCII values. Note that using ASCII, all capital letters come before all lower case letters. 4. Once the program has read all the input (when EOF is returned or a blank line encountered), the program then performs an in-order traversal of the binary search tree to print out all the strings one line at a time to the output file or stdout. Next to the line include a count of how many times that line appeared. If the selection was for case insensitive then you should include either the first choice encountered, the last choice encountered or all capital letters. 5. Before the program ends, it must reclaim the tree! You can do this by performing a post-order traversal, i.e., reclaiming the children nodes before reclaiming the node itself. Make sure you also reclaim the memory occupied by the string as well. 6. It is required that you use getopt for processing the command line and use malloc or calloc and free functions for dynamically allocating and deallocating nodes and the buffers for the strings. It is required that you implement your own string comparison functions instead of using the corresponding libc functions. Here's an example: bash$ cat myfile bob is working. david is a new hire. Bob is working. alice is bob's boss. charles doesn't like bob. bash$ ./bstsort myfile 1 alice is bob's boss. 2 bob is working. 1 charles doesn't like bob. 1 david is a new hire. Please submit your work through the inbox as one zip file. Follow the instructions below carefully (to avoid unnecessary loss of grade): You should submit the source code and the Makefile in the zip file called FirstnameLastnameA1. One should be able to create the executable by simply 'make'. The Makefile should also contain a 'clean' target for cleaning up the directory (removing all temporary files and object files). Make sure you don't include intermediate files: *.o, executables, *~, etc., in your submission. (There'll be a penalty for including unnecessary intermediate files). Only two files should be included unless permission is given for more, those would be bstsort.c, and Makefile. If you feel a need to include a bstsort.h file, please send me a note asking for permission. Late submissions will have a deduction as per the syllabus. • If the program does not compile and do something useful when it runs it will not earn any credit. • If a program is plagiarized, it will not earn any credit. • If a program uses a bstsort.h file without permission it will not earn any credit.

In: Computer Science

You have a choice of handling a binary classification task using number of misclassifications as the...

You have a choice of handling a binary classification task using number of misclassifications as the performance measure and maximizing the margin between the two classes as the performance measure. On what factors does your decision depend? Provide a formal explanation, supported by theorems and ideas

In: Computer Science

[1] Can you load a Linux kernel module more than once? Explain briefly. [1] For the...

  1. [1] Can you load a Linux kernel module more than once? Explain briefly.

  2. [1] For the modules we have created in class, does the code run continuously, or does it run in response to certain events? Explain, and be specific.

  3. [1] When the kernel does a printk(), does it write directly to /var/log/kern.log? Explain.

  4. [1] The makefile for a Linux kernel module is generally very simple; however, building a module seems to be a bit complicated, generating lots of files. Where is the module build process getting instructions for doing all this work?

  5. [1] If you change line 22 in the ones module to define CLASS_NAME to be "OSclass", will this change the observable behavior of the module? Explain briefly.

  6. [1] When doing the work for a system call, how does the kernel keep track of which process made that system call (so it does the work on behalf of that process)?

  7. [2] How does the format of data returned by getdents(2) differ from that returned by readdir(3) (at a high level)? What is a key motivation for this difference?

  8. [2] How can you change the magic_prefix for the rootkit without changing the code of the module? How is this information passed to the kernel at runtime?

  9. [2] When the kernel allocates memory for its own use, does it refer to that memory using virtual or physical addresses? How does the remember module show this?

  10. [2] What is a significant reason why the kernel uses functions such as copy_to_user() when accessing process memory? Why not just access this memory directly?

  11. [2] Change the ones module so that it will allow writes, and the first character of whatever is written will become the character that is repeatedly output when reading (instead of '1'). What changes do you need to make?

  12. [4] How could you make a "spooky rootkit" (based on 3000rootkit) that would randomly (with a .01 probability on each call to getdents) insert a file "BOO!" with an inode of 9999 into the stream of returned files? Note that you can get random bytes using the get_random_bytes() function in the kernel.

In: Computer Science

In this programming assignment, you are asked to write a multi-threaded program using JAVA to compute...

  1. In this programming assignment, you are asked to write a multi-threaded program using JAVA to compute the sum of an arithmetic series from 1 to 200 using pthreads.   The main thread is responsible for creating two child threads

  1. The first child thread should compute the partial sum of the series from 1 to 100 and the second computes the partial sum of another series from 101 to 200.

  1. The main thread should accumulate the partial sums computed by the child threads to obtain the final sum and then print out the results, including the partial sums computed by each child thread and the final sum accumulated by the main thread.

In: Computer Science

Write a program that calculates mean and standard deviation for four user entered values. The most...

Write a program that calculates mean and standard deviation for four user entered values. The most common measures of a sample are the mean and the standard deviation. the mean is the sum of the values divided by the number of elements in the data set. The dispersion - or spread in the values - is measured by the standard deviation The equation for the mean is x¯ = x1 + x2 + · · · + xn The equation for the standard deviation is sx = √ (x1 − x¯) 2 + (x2 − x¯) 2 + · · · + (xn − x¯) 2 n − 1 Your program will have the user enter four values (all doubles), You might call them x1, x2,x3,and x4. The program will then pass these four values to a function called mean that will calculate and return the mean of the four values. The mean and the four values will then be passed to a second function called stdev which will calculate and return the standard deviation of the four values. You program should be using functions. There will be a function printHeader that prints the splash screen, a function mean that calculates the mean, a function stdev that calculates the standard deviation, and a function printResults that prints the four values, their mean, and their standard deviation Your program must also include comments with your name, the date, and a short description of the project. It must also print this information as a splash screen at the beginning of the program run. It should print like:

X: 4.00, 7.00, 1.00, 10.00

Mean: 5.50

Std Dev: 3.87

This needs to be done in C++. Below is the format:

//
//   Name
// 1 October 2020
//   Program to calculate the mean and standard deviation
//

//   Pound includes - will need the string and cmath libraries
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>

using namespace std;

//   Function Prototypes - Need to add three more. One for mean, one for
// standard deviation, and one for the printResults
void printHeader(string, string);
int main(void) {

   // Splash Screen
   printHeader("1 October 2020", "Calculating Statistics");
  
   //   Declare and Initialize all of the variables
   //   Will need doubles for the four data points, as well as a double
// for the mean and one for the standard deviation
  
  
   //   Prompt for entering data - you must enter four values
  
  
   // Pass the four data variables to a function that returns the mean
  
  
  
   //   Pass the four data variables and the mean to a function that returns
// the standard deviation
  
  
  
  
   //   Print the results
   //   Include the original values and the mean and the standard
// DO NOT PRINT IT HERE - pass the variables to a printResults function
  
  
  
  
  
   return 0;
}

//   Function Definitions
void printHeader(string dueDate, string description) {
//   PRINTHEADER void printHeader(string, string) prints the splash screen
//   using the two strings that are passed to the function from the driver.
//  
//   Name:   
//   Date:
//
  
   //   Print the splash screen
   cout << endl;
   cout << "Your Name Here" << endl;
   cout << "CMPSC 101" << endl;
   cout << dueDate << endl;
   cout << description << endl;
   cout << endl;


   return;
}

In: Computer Science

How is it possible for the network layer (L3) to operate in connectionless, best effort manner?...

How is it possible for the network layer (L3) to operate in connectionless, best effort manner? Hint: think upper layer

In: Computer Science

What command lists the MAC address on a computer? how do you find it on a...

What command lists the MAC address on a computer? how do you find it on a mobile devices?

In: Computer Science

Implement a function that returns all the items in a binary search tree in order inside...

Implement a function that returns all the items in a binary search tree in order inside a std::vector. Use the following class and function definition:

class BTNode {
public:
   int item;
   BTNode *left;
   BTNode *right;
   BTNode(int i, BTNode *l=nullptr, BTNode *r=nullptr):item(i),left(l),right(r){}
};

BTNode *root = nullptr;

std::vector<int> inorder_traversal(BTNode *node) {
     // implement
}

If the BST has no values, return a vector with no items in it.

#include <iostream>
#include <vector>

class BTNode {
public:
int item;
BTNode *left;
BTNode *right;
BTNode(int i, BTNode *l=nullptr, BTNode *r=nullptr):item(i),left(l),right(r){}
};

BTNode *root = nullptr;

std::vector<int> inorder_traversal(BTNode *node) {
// implement
}

int main()
{
root = new BTNode(10, new BTNode(0), new BTNode(100));

std::vector<int> res = inorder_traversal(root);

for(auto &i : res) {
std::cout << i << ", ";
}
std::cout << std::endl;


return 0;
}

In: Computer Science

The following is an infinite loop: for (int i = 0; i < 10; i++); System.out.println(i...

The following is an infinite loop:

for (int i = 0; i < 10; i++);
System.out.println(i + 4);

TRUE OR FALSE?

In: Computer Science

In python design a simple program that lets the user enter the total rainfall for each...

In python design a simple program that lets the user enter the total rainfall for each of the last 10 years into an array. The program should calculate and display the total rainfall for the decade, the average yearly rainfall, and the years with the highest and lowest amounts. Have screenshot with indentation and output display with explantion.Include comments

In: Computer Science

Again, recall Little’s Law. An escalator can be used two ways: A person can stand and...

Again, recall Little’s Law. An escalator can be used two ways: A person can stand and let the escalator take her to the other end. Or the person can walk the escalator, reaching the other end faster. Suppose by walking a person reaches the other end in 60% of the time she takes just standing. However, when all walk the escalator, they need more space between them to avoid bumping into each other. Thus, the number of persons who can be on the escalator at the same time reduces by 50%. Which method (everyone standing vs. everyone walking) allows escalator to be used by most people per unit of time? Explain briefly. For full credit, you must use Little's Law to prove it.

In: Computer Science

A.) 1. Write a loop that prints the numbers 1-25i.e. B.) 1 2 3 4... 252....

A.) 1. Write a loop that prints the numbers 1-25i.e.

B.) 1 2 3 4... 252. Write a loop that prints all the even numbers between 1 and 50i.e. 2 4 6 8... 483.

C.) Create a list of the following fruits: oranges, apples, grapes and mangos and cherries. Write a loop that prints out every other fruit starting with oranges.i.e. oranges grapes and cherries.

In: Computer Science

Implement a function to find a node in a binary search tree. Using the following class...

Implement a function to find a node in a binary search tree. Using the following class and function definition:

class BTNode {
public:
   int item;
   BTNode *left;
   BTNode *right;
   BTNode(int i, BTNode *l=nullptr, BTNode *r=nullptr):item(i),left(l),right(r){}
};

BTNode *root = nullptr;

BTNode* find(int i) {
     // implement
}

If a node with a matching value is found, return a pointer to it. If no match is found, return nullptr.

#include <iostream>

class BTNode {
public:
int item;
BTNode *left;
BTNode *right;
BTNode(int i, BTNode *l=nullptr, BTNode *r=nullptr):item(i),left(l),right(r){}
};

BTNode *root = nullptr;

BTNode *find(int item)
{
return nullptr;
}

int main()
{   
root = new BTNode(10, new BTNode(1), new BTNode(20));

BTNode *t1 = find(10);
if (t1)
std::cout << "Found " << t1->item << std::endl;
else
std::cout << "Should have found 10." << std::endl;

  
BTNode *t2 = find(1);
if (t1)
std::cout << "Found " << t2->item << std::endl;
else
std::cout << "Should have found 1." << std::endl;

BTNode *t3 = find(20);
if (t3)
std::cout << "Found " << t3->item << std::endl;
else
std::cout << "Should have found 20." << std::endl;

BTNode *t4 = find(100);
if (t4)
std::cout << "Should have found 20." << std::endl;   
else
std::cout << "Did not find 100." << std::endl;
  

return 0;
}

In: Computer Science

Write a class called Person that has two private data members - the person's name and...

Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method.

Write a separate function (not part of the Person class) called basic_stats that takes as a parameter a list of Person objects and returns a tuple containing the mean, median, and mode of all the ages. To do this, use the mean, median and mode functions in the statistics module. Your basic_stats function should return those three values as a tuple, in the order given above.

For example, it could be used as follows:
p1 = Person("Kyoungmin", 73)
p2 = Person("Mercedes", 24)
p3 = Person("Avanika", 48)
p4 = Person("Marta", 24)
person_list = [p1, p2, p3, p4]
print(basic_stats(person_list)) # should print a tuple of three values
The files must be named: basic_stats.py

In: Computer Science