Write a C program that repeatedly prompts the user for input at a simple prompt (see the sample output below for details). Your program should parse the input and provide output that describes the input specified. To best explain, here's some sample output:
ibrahim@ibrahim-latech:~$ ./prog1
$ ls -a -l -h
Line read: ls -a -l -h
Token(s):
ls
-a
-l
-h
4 token(s) read
$ ls -alh
Line read: ls -alh
Token(s):
ls
-a
-l
-h
2 token(s) read
$ clear
Line read: clear
Token(s):
clear
1 token(s) read
$ exit ibrahim@ibrahim-latech:~$
Note that the first and last lines are not part of program output (i.e., they are of the terminal session launching the program and after its exit). The program prompts the user (with a simple prompt containing just a $ followed by a space) and accepts user input until the command exit is provided, at which point it exits the program and returns to the terminal. For all other user input, it first outputs the string Line read: followed by the user input provided (on the same line). On the next line, it outputs the string Token(s):. This is followed by a list of the tokens in the input provided, each placed on a separate line and indented by a single space. For our purposes, a token is any string in the user input that is delimited by a space (i.e., basically a word). The string n token(s) read is then outputted on the next line (of course, n is replaced with the actual number of tokens read). Finally, a blank line is outputted before prompting for user input again. The process repeats until the command exit is provided. Hints: (1) An array of 256 characters for the user input should suffice (2) To get user input, fgets is your friend (3) To compare user input, strcmp is your friend (4) To tokenize user input, strtok is your friend Turn in your .c source file only that is compilable as follows (filename doesn't matter): gcc -o prog1 prog1.c Make sure to comment your source code appropriately, and to include a header providing your name.
In: Computer Science
In C++, dealing with Binary Search trees. Implement search, insert, removeLeaf, and removeNodeWithOneChild methods in BST.h. BST.h code below
#include <iostream> #include "BSTNode.h" using namespace std; #ifndef BST_H_ #define BST_H_ class BST { public: BSTNode *root; int size; BST() { root = NULL; size = 0; } ~BST() { if (root != NULL) deepClean(root); } BSTNode *search(int key) { // complete this method } BSTNode *insert(int val) { // complete this method } bool remove(int val) { // complete this method } private: void removeLeaf(BSTNode *leaf) { // complete this method } void removeNodeWithOneChild(BSTNode *node) { // complete this method } static BSTNode *findMin(BSTNode *node) { if (NULL == node) return NULL; while (node->left != NULL) { node = node->left; } return node; } static BSTNode *findMax(BSTNode *node) { if (NULL == node) return NULL; while (node->right != NULL) { node = node->right; } return node; } void print(BSTNode *node) { if (NULL != node) { node->toString(); cout << " "; print(node->left); print(node->right); } } static int getHeight(BSTNode *node) { if (node == NULL) return 0; else return 1 + max(getHeight(node->left), getHeight(node->right)); } static void deepClean(BSTNode *node) { if (node->left != NULL) deepClean(node->left); if (node->right != NULL) deepClean(node->right); delete node; } public: int getTreeHeight() { return getHeight(root); } void print() { print(root); } int getSize() { return size; } }; #endif
This is the expected output
****************** Test BST Correctness ******************
Inserting the following numbers: [11, 12, 15, 17, 12, 19, 4, 5, 11,
19, 20, 32, 77, 65, 66, 88, 99, 10, 8, 19,
15, 66, 11, 19]
*** BST Structure (after insertion) ***
<11, null> <4, 11> <5, 4> <10, 5> <8,
10> <12, 11> <15, 12> <17, 15> <19, 17>
<20, 19> <32, 20> <77,
32> <65, 77> <66, 65> <88, 77> <99,
88>
Size of BST: 16
*** Searching BST ***
Found: [19, 12, 4, 5, 19, 20, 32, 99, 8, 12]
Did not find: [29, 3, 27, 34, 45, 37, 25, 25, 24, 16]
*** Deleting BST ***
Deleted: [12, 15, 5, 17, 19, 4, 20, 32, 99, 10, 8]
Did not find: [16, 5, 19, 17, 19, 39, 19, 15, 21]
*** BST Structure (after deletion) ***
<11, null> <77, 11> <65, 77> <66, 65>
<88, 77>
Size of BST: 5
****************** Clean up ******************
Size of hash table: 0
Size of BST: 0
In: Computer Science
Suppose you have the following list of integers to sort:
[1, 5, 4, 2, 18, 19]
which list represents the partially sorted list after three complete passes of insertion sort?
1 2 4 5 18 19 |
||
1 4 5 2 18 19 |
||
1 4 2 5 18 19 |
||
None of the above |
In: Computer Science
How does S/4HANAempower digital supply chain? Provide some examples on how this system is benefiting organisations to compete?
In: Computer Science
Apply the different components of systems thinking on the zillow business scenario. In other words, the different components of Zillow as system, the input, the output, and the different feedbacks.
In: Computer Science
C++ please
You have been challenged with a menu program before, but this one is a little more complex. You will use loops and you will use an output file for a receipt.
Using class notes, write an algorithm for a program which uses a loop system to allow customers to select items for purchase from a list on the screen. (List at least 8 items to choose from on your menu. You choose the items to be listed.).
When the user is finished choosing items, display the amount due and then accept the customer's payment. If the customer pays enough, display change due on the screen.
If the customer does not pay enough, use another loop system to get additional payment from the customer until the total due has been paid. When finished, have an output file that lists all items purchased along with prices, the subtotal, the tax amount, the grand total and total paid.
In: Computer Science
In: Computer Science
Write a python code using a continuous random variable and using uniform distribution to output the expected weight of students in a class.
In: Computer Science
In: Computer Science
This is JAVA PROGRAMMING
Sort the contents of the two files in ascending order and
combine them into one new file (words.txt).
When comparing string order, you must use the compareTo method and
make an exception.The source code below is a code that only
combines files. Use the comparedTo method to sort the contents of
the two files in ascending order.(ex. if(str1.compareTo(str2)<0)
{})
<file1.txt>
at first
castle
consider
considerable
enlighten
explain
explanation
female
<file2.txt>
consideration
considering that
education
educational
endow
inherit
<code>
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Lab7_1 {
public static void main(String[] args) {
// TODO Auto-generated method
stub
fileMerge("file1.txt","file2.txt","words.txt");
}
private static void fileMerge(String filename1, String
filename2, String filename3) {
// TODO Auto-generated method
stub
Scanner str1=null;
Scanner str2=null;
PrintWriter output=null;
try {
str1 = new
Scanner(new File(filename1));
str2 = new Scanner(new File(filename2));
output = new PrintWriter(new
File(filename3));
fileWriter(str1,output);
fileWriter(str2,output);
} catch (FileNotFoundException e)
{
// TODO
Auto-generated catch block
System.err.println(e.getMessage());
//
e.printStackTrace();
} finally {
if (str1 !=
null)
str1.close();
if (str2 !=
null)
str2.close();
if (output !=
null)
output.close();
}
}
private static void
fileWriter(Scanner str1, PrintWriter output) {
// TODO
Auto-generated method stub
while(str1.hasNextLine()) {
String str = str1.nextLine();
output.println(str);
}
}
}
In: Computer Science
A new implementation of Merge Sort uses a cutoff variable to use insertion sort for small number of items to be merged (Merging single elements is costly).
1. Give the pseudo code for the merge sort algorithm with a cutoff variable set to 4.
2. Show the trace for top-down merge sort using the following array of characters with a cutoff variable set to 4.
E A S Y M E R G E S O R T W I T H I N S E R T I O N
In: Computer Science
Program a math quiz on Python
Specifications:
- The program should ask the user a question and allow the student to enter the answer. If the answer is correct, a message of congratulations should be displayed. If the answer is incorrect, a message showing the correct answer should be displayed.
- the program should use three functions, one function to generate addition questions, one for subtraction questions, and one for multiplication questions.
- the program should store the questions and answers in a dictionary or list.
- the program should keep a count of the number of correct and incorrect responses.
In: Computer Science
Consider the following ER diagram, which models an online bookstore.
As per the attached picture in the attached link :
https://www.google.com/imgres?imgurl=https://media.cheggcdn.com/study/45a/45a5708f-f2b8-4864-99a3-284d8c13e235/5924-7-20EEI1.png&imgrefurl=https://www.chegg.com/homework-help/consider-e-r-diagram-figure-729-models-online-bookstore-lis-chapter-7-problem-20e-solution-9780073523323-exc&tbnid=q173_TY0HXF25M&vet=1&docid=hPpMlzEq8SYJYM&w=756&h=688&hl=en&source=sh/x/im
A. List the entity sets and their primary keys.
B. Map the ER to appropriate schema showing the different relations.
In: Computer Science
In php:
After completed, the website should hide all messages before the user click submit button OR show either the error message or success message if the user click submit button.
//code
<?php
if(isset($_GET['submit'])){
//sanitize the input
/* Check the error from the input:
if input from user is empty
-> get an error string variable
if input is not empty
-> use preg_match() to match the pattern
$pattern = "/^[1-9][0-9]{2}(\.|\-)[0-9]{3}(\.|\-)[0-9]{4}$/";
-> if it's a matched, get a success string variable
*/
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,
initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z"
crossorigin="anonymous">
<link rel="stylesheet" href="">
<title>Lab 2-Part1</title>
</head>
<body>
<form action="" class="main-form
needs-validation">
<div class="form-group">
<label for="numbers">Phone Number</label>
<input type="text" id="numbers" class="form-control"
value=<?php //use PHP to print out the value the use typed in if
any ?>>
<small class="form-text text-muted">xxx.xxx.xxx or
xxx-xxx-xxxx</small>
<!-- Set a condition
if there is an error string variable, print out the string in
PHP
if there is a success string variable, print out the string in
PHP
-->
<div class="alert
alert-danger">
Must enter a valid
phone number! <!-- should be from an error string variable
-->
</div>
<div class="alert
alert-success">
Phone number is valid!
<!-- should be from an error string variable -->
</div>
</div>
<button type="submit" class="btn btn-primary"
>Submit</button>
</form>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS
-->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"></script>
</body>
</html>
In: Computer Science
Write a Python program that reads an integer and prints how many digits the number has, by checking whether the number is ≥10,≥100,≥1000, and so on (up to 1,000,000). Your program should also identify if a number is negative.
In: Computer Science