A certain programming language allows only two-character variable names. The first character must be a letter (upper or lower case) and the second character can be a letter (upper or lower case) or a digit. How many possible variable names are there?
In: Computer Science
c++
Run the following sorting algorithms:
1. Bubble sort
2. Insertion sort
3. Quicksort
4. Mergesort
Under the following scenarios for input data:
1. Uniform random
2. Almost sorted (90% sorted – 1 in 10 is out of place)
3. Reverse sorted
On data of sizes 5,000, 10,000, … in increments of 5,000 up to …,
50,000
-Attach a screenshot of a program compilation below
-Attach a screenshot of a successful program run below
-Attach a graph (either line graph or bar graph) below.
3.2 90% Sorted Data (10% of data are out of their sorted
position)
--Attach a graph below
3.3 Reverse-Sorted (sorted in non-increasing order) Data
--Attach a graph below
template code:
//a main template file
#include <iostream>
#include <iomanip>
#include <ctime>
#include <string>
#include "Sort.h"
using namespace std;
void init_and_run(double**, int*, const int, const int, const int,
const int);
void print(double**, int*, const int, const int, const int, const
int);
int main()
{
int size[] = {100, 1000, 5000, 10000, 50000};
const int NUM_SIZES = 7;
const int NUM_SORT_ALGO = 7;
const int NUM_DATA_TYPES = 3;
const int NUM_REPEAT = 5;
double* totalSortTime[NUM_DATA_TYPES];
init_and_run(totalSortTime, size, NUM_SIZES, NUM_DATA_TYPES,
NUM_SORT_ALGO, NUM_REPEAT);
print(totalSortTime, size, NUM_SIZES, NUM_DATA_TYPES,
NUM_SORT_ALGO, NUM_REPEAT);
return 0;
}
void init_and_run(double**totalSortTime, int* size, const int
NUM_SIZES, const int NUM_DATA_TYPES, const int NUM_SORT_ALGO, const
int NUM_REPEAT)
{
clock_t time;
for(int d = 0; d < NUM_DATA_TYPES; d++) {
totalSortTime[d] = new double [NUM_SIZES * NUM_SORT_ALGO];
for(int i = 0; i < NUM_SIZES * NUM_SORT_ALGO; i++)
totalSortTime[d][i] = 0;
}
for(int d = 0; d < NUM_DATA_TYPES; d++) { //data types
for(int s = 0; s < NUM_SIZES; s++) { //input sizes
for(int r = 0; r < NUM_REPEAT; r++) { //repetitions
Sort st(size[s], d);
for(int t = 0; t < NUM_SORT_ALGO; t++) { //sort algorithms
st.setSortType(t);
time = clock();
st.run();
//st.print();
time = clock() - time;
totalSortTime[d][s * NUM_SORT_ALGO + t] += time;
}
}
}
}
for(int d = 0; d < NUM_DATA_TYPES; d++) {
delete [] totalSortTime[d];
}
}
void print(double**totalSortTime, int* size, const int NUM_SIZES,
const int NUM_DATA_TYPES, const int NUM_SORT_ALGO, const int
NUM_REPEAT)
{
//cout << string(25, '=') << " AVG SORTING TIME "
<< string(25, '=') << endl;
cout << "\nEach value displayed below shows the average
sorting time with five instances.\n";
cout << "The values may vary depending on the system and the
implementation.\n";
cout << "The relative performances, however, should be the
same.\n";
cout << "So are the performances of those algorithms as N or
% of sorted numbers grows." << endl;
string dataType[NUM_DATA_TYPES] = {
" RANDOM_TBL_SIZE ",
// " TBL_SIZE_PARTIAL_SORT_25 ",
// " TBL_SIZE_PARTIAL_SORT_50 ",
// " TBL_SIZE_PARTIAL_SORT_75 ",
" TBL_SIZE_PARTIAL_SORT_95 ",
" REVERSE_SORTED "
};
string sortAlgo[NUM_SORT_ALGO] = {
"INSERTION",
"MERGESORT",
"QUICKSORT_L",
"QUICKSORT_R",
"COUNTING"
"BUBBLE",
"SELECTION"
};
cout << fixed << setprecision(2) << endl;
for(int d = 0; d < NUM_DATA_TYPES; d++) {
cout << string(25, '-') << left << setw(26)
<< dataType[d] << string(25, '-') << endl;
cout << right << setw(7) << "N";
for(int a = 0; a < NUM_SORT_ALGO; a++)
cout << right << setw(14) << sortAlgo[a];
cout << endl;
for(int s = 0; s < NUM_SIZES; s++) {
cout << right << setw(7) << size[s];
for(int t = 0; t < NUM_SORT_ALGO; t++)
cout << right << setw(14) << totalSortTime[d][s *
NUM_SORT_ALGO + t]/NUM_REPEAT;
cout << endl;
}
cout << endl;
}
}
#ifndef DATAGEN_H
#define DATAGEN_H
class DataGen {
private:
int modType;
int sortType;
int dataType;
int** data;
int inputSize;
int arraySize;
int partialSortSize;
void getRandom();
void copy();
void partialSort();
public:
DataGen();
DataGen(int*[], int, int, int);
void generateData();
//void partialSort();
};
#endif
#include "DataGen.h"
class Sort
{
friend class DataGen;
private:
int* numbers[5];
int algo_types;
int size;
DataGen *dg;
void (Sort::*fp) ();
void insertionSort();
void bubbleSort();
void selectionSort();
void mergeSort();
void quickSort_L();
void quickSort_R();
void countingSort();
void partition_L(int, int, int&, int&);
void partition_R(int, int, int&, int&);
void merge(int, int, int[]);
void recursive_mergeSort(int, int, int[]);
void recursive_quickSort_L(int, int);
void recursive_quickSort_R(int, int);
void clear();
public:
Sort(int, int);
~Sort();
void setSortType(int);
void run();
void print();
};
#endif
In: Computer Science
Write a two paragraph description of hashing that a non-technical user could understand .
In: Computer Science
JAVA
Write a program that demonstrates how various exceptions are caught with
catch (Exception exception)
This time, define classes ExceptionA (which inherits from class Exception) and ExceptionB (which inherits from class ExceptionA). In your program, create try blocks that throw exceptions of types ExceptionA, ExceptionB, NullPointerException and IOException. All exceptions should be caught with catch blocks specifying type Exception.
In: Computer Science
(SQL Coding)
Create a read only view called view_emp_salary_rank_ro that selects the last name and salary from the o_employees table and ranks the salaries from highest to lowest for the top three employees.
In: Computer Science
Write a program with two input values, Hours and Rate. The program should first calculate Gross pay, which is your pay before deductions. The program should then calculate the following three deduction amounts: Federal Tax (20% of Gross), State Tax (5% of Gross), Social Security Tax (6.2% of Gross). Then your program should calculate Net pay, which is your Gross pay minus the three deductions. The output should be all five of the calculated values.
In: Computer Science
JAVA PROGRAM, Create the game "Rock, Scissor, Paper":
In: Computer Science
For each of the following scenarios / consumers, to which type
of Cloud service model is it best suited?
1) Using Cloud storage for long-term archiving of financial
records.
2) Outsourcing an organization’s VoIP IT systems to public Cloud providers.
In: Computer Science
Program 3: Command Line Calculator
Topics: Functions or methods, global variables
Overview
You will build a simple command line calculator. It supports addition (add), subtraction (sub), multiplication (mul), division (div), and calculation of the absolute value (abs). You will use functions to support each type of calculation. You can assume that the numbers are float data types.
Software Specifications
The user interacts with program by entering a command, followed by some parameters at the command prompt “>”. For example, if the user wants to add 4 and 5, he/she enters “add 4 5” and hits the return key. The system then outputs the result of the addition command (in this case, 9). See sample run output below for more examples.
Once the command’s operation is completed, the system goes back to the command prompt waiting for another command from the user. The commands are “add”, “sub”, “mul”, “div”, and “abs”. All the commands take two arguments except for “abs” which takes one argument. Each command will call the corresponding function to perform the calculation. Name each function the same name as the command. The “quit” command calls the printStats function and ends the program. The printStats function prints the number of times each function were called (executed). To keep track of function call usage, you will need global variables which can be shared across functions.
Command |
# of arguments |
Behavior |
add |
2 |
Adds the two arguments. |
sub |
2 |
Subtracts the second argument from the first argument. |
mul |
2 |
Multiplies the two arguments. |
div |
2 |
Divides the first argument by the second argument. If the second argument is 0, print “Error: Division by zero” and return 0. |
abs |
1 |
Computes the absolute value of the argument. |
quit |
0 |
Prints the function usage statistics, and ends the program. |
Parsing the command line
Your program will read the command as a single line. It then splits it into several tokens. The first is the command. Any other tokens after the first are the parameters. To parse a command, simply use the split function on the string. Don’t forget to convert the parameters to floats so that you can perform arithmetic operations.
The code below shows you how to use the split function to extract the command and the parameters.
>>> userinput="add 1 2"
>>> tokens = userinput.split(" ")
>>> print(tokens[0])
add
>>> print(tokens[1])
1
>>> print(tokens[2])
2
Sample Outputs
Welcome to iCalculator.
>add 3 4.0
7.0
>mul 3 5
15.0
>abs 5
5.0
>abs -7
7.0
>abs 8
8.0
>quit
Function usage count
add function : 1
sub function : 0
mul function : 1
div function : 0
abs function : 3
In: Computer Science
Implement a stack in C++ using an array, not an array list.
Make your stack size 5 when you test it, but do not hardcode this! You should be able to change the size for testing purposes with the change of one variable.
DO NOT use Stack class defined in C++
Implement the following methods in your stack class.
Write your own Driver file to show that you have implemented all the methods of the stack. A psuedocode example is listed below to guide you. Use print statements as well to show the popped elements, to show the stack after some pushes, to print the size of the stack.
In: Computer Science
Python - Rewriting a Program
Rewrite Program 1 using functions. The required functions are in the table below.
Create a Python program that will calculate the user’s net pay based on the tax bracket he/she is in. Your program will prompt the user for their first name, last name, their monthly gross pay, and the number of dependents.
The number of dependents will determine which tax bracket the user ends up in. The tax bracket is as follows:
After calculating the net pay, print the name of the user, the monthly gross pay, the number of dependents, the gross pay, the tax rate, and the net pay.
The formula to compute the net pay is: monthly gross pay – (monthly pay * tax rate)
function |
Description |
read_name() |
Reads the name entered, and returns the name. |
read_gross_pay() |
Reads the gross pay amount, and returns the amount. |
read_dependents() |
Reads the number of dependents, and returns the number. |
compute_tax_rate(dependents) |
Computes and returns the tax rate, based on the number of dependents. |
compute_net_pay(gross_pay, rate) |
Computes and returns the net pay, based on the gross pay and the tax rate. |
main() |
Main function of the program. |
Sample run:
Enter your name: Ron Swanson
Enter your gross pay: $3500
Enter number of dependents: 0
Name: Ron Swanson
Gross pay: $3500.00
Dependents: 0
Tax rate: 20%
Net Pay: $2800.00
In: Computer Science
Simplify (A xor B) + (A xor C) using K-maps, does (A xor B) + (B xor C) have the same K-map?
In: Computer Science
•A theater owner agrees to donate a portion of gross ticket sales to a charity
•The program will prompt the user to input:
−Movie name
−Adult ticket price
−Child ticket price
−Number of adult tickets sold
−Number of child tickets sold
−Percentage of gross amount to be donated
•Inputs: movie name, adult and child ticket price, # adult and child tickets sold, and percentage of the gross to be donated
•The program needs to:
1.Get the movie name
2.Get the price of an adult ticket price
3.Get the price of a child ticket price
4.Get the number of adult tickets sold
5.Get the number of child tickets sold
PLEASE USE C++
In: Computer Science
How do I make sure that this C code shows the letter P for one second then L a second later on a raspberry pi sense hat?
How do I make sure that this C code shows the letter P for one second then L a second later on a raspberry pi sense hat?
1 #include <stdio.h>
2 #include <unistd.h>
3 #include "sense.h"
4
5 #define WHITE 0xFFFF
6
7 int main(void) {
8 // getFrameBuffer should only get called
once/program
9 pi_framebuffer_t
*fb=getFrameBuffer();
10 sense_fb_bitmap_t
*bm=fb->bitmap;
11
12
13 // Letter P
14 bm->pixel[0][0]=WHITE;
15 bm->pixel[0][1]=WHITE;
16 bm->pixel[0][2]=WHITE;
17 bm->pixel[0][3]=WHITE;
18 bm->pixel[0][4]=WHITE;
19 bm->pixel[0][5]=WHITE;
20 bm->pixel[1][5]=WHITE;
21 bm->pixel[2][5]=WHITE;
22 bm->pixel[3][5]=WHITE;
23 bm->pixel[3][4]=WHITE;
24 bm->pixel[3][3]=WHITE;
25 bm->pixel[2][3]=WHITE;
26 bm->pixel[1][3]=WHITE;
27
28 /*
29 void drawCFB(void);
30 drawCFB();
31 */
32
33 sleep(1);
34
35
bm->pixel[0][0]=WHITE;
36 bm->pixel[0][1]=WHITE;
37 bm->pixel[0][2]=WHITE;
38 bm->pixel[0][3]=WHITE;
39 bm->pixel[0][4]=WHITE;
40 bm->pixel[0][5]=WHITE;
41 bm->pixel[1][0]=WHITE;
42 bm->pixel[2][0]=WHITE;
43 bm->pixel[3][0]=WHITE;
44
45
sleep(1);
46
47 return
0;
48 }
In: Computer Science
1) The provided reorder.cpp file has some code for a function that reorders the values in 3 parameters so that they are in ascending order.
·Start with a function void swap(int &val1, int &val2) that swaps the values of val1 and val2. You will need a local variable to hold the value of one of the parameters to let you do this.
·Write the reorder function called in main(). It should call swap() to exchange values when appropriate.
·Add statements to main() to be able to try out the 3 cases below
Driver to test reorder()
Case 1: values are already in correct order -- leave them alone
1 2 3
Case 2: first > second and first < third
-5 -2 0
Case 3: first > second > third
6 8 10
reorder.cpp
// Reordering values in variables #include <iostream> using namespace std; // swap the values in the two reference integer parameters void swap(int &val1, int &val2) { } // reorder 3 integer values so that // first parameter has smallest value, second parameter has middle value, // third parameter has largest value int main() { int val1 = 1, val2 = 2, val3 = 3; cout << "Driver to test reorder()" << endl; cout << "Case 1: values are already in correct order -- leave them alone" << endl; reorder(val1, val2, val3); cout << val1 << " " << val2 << " " << val3 << endl; return 0; }
In: Computer Science