i need to find complexity and cost and runtime for each line of the following c++ code :
// A C++ program for Dijkstra's single source shortest path
algorithm.
// The program is for adjacency matrix representation of the
graph
#include <limits.h>
#include <stdio.h>
// Number of vertices in the graph
#define V 9
// A utility function to find the vertex with minimum distance
value, from
// the set of vertices not yet included in shortest path tree
int minDistance(int dist[], bool sptSet[])
{
// Initialize min value
int min = INT_MAX, min_index;
for (int v = 0; v < V; v++)
if (sptSet[v] == false &&
dist[v] <= min)
min = dist[v],
min_index = v;
return min_index;
}
// A utility function to print the constructed distance
array
void printSolution(int dist[])
{
printf("Vertex \t\t Distance from Source\n");
for (int i = 0; i < V; i++)
printf("%d \t\t %d\n", i,
dist[i]);
}
// Function that implements Dijkstra's single source shortest
path algorithm
// for a graph represented using adjacency matrix
representation
void dijkstra(int graph[V][V], int src)
{
int dist[V]; // The output array. dist[i] will hold
the shortest
// distance from src to i
bool sptSet[V]; // sptSet[i] will be true if vertex
i is included in shortest
// path tree or shortest distance from src to i is
finalized
// Initialize all distances as INFINITE and
stpSet[] as false
for (int i = 0; i < V; i++)
dist[i] = INT_MAX, sptSet[i] =
false;
// Distance of source vertex from itself is always
0
dist[src] = 0;
// Find shortest path for all vertices
for (int count = 0; count < V - 1; count++) {
// Pick the minimum distance vertex
from the set of vertices not
// yet processed. u is always equal
to src in the first iteration.
int u = minDistance(dist,
sptSet);
// Mark the picked vertex as
processed
sptSet[u] = true;
// Update dist value of the
adjacent vertices of the picked vertex.
for (int v = 0; v < V; v++)
// Update
dist[v] only if is not in sptSet, there is an edge from
// u to v, and
total weight of path from src to v through u is
// smaller than
current value of dist[v]
if (!sptSet[v]
&& graph[u][v] && dist[u] != INT_MAX
&& dist[u] + graph[u][v] <
dist[v])
dist[v] = dist[u] + graph[u][v];
}
// print the constructed distance array
printSolution(dist);
}
In: Computer Science
URGENT JAVA
Develop a Java computer program to simulate access control to a system network. The username and password authentication mechanism is used as an access control mechanism in this project. The program needs to authenticate the user with their username and hashed password stored in Access Manager User (AMU) file. To create an Access Manager User file, you need to develop a java program that takes username and password as input and then generates a file containing the username, hashed password, and plaintext password. In real world, the plaintext are not saved in the AMU file. However, you need the username and corresponding plaintext password for testing of your main program. The structure of the AMU file is shown in the appendix. Note that this should be done as a separate program. The main program operates in the following manner. It first prompts the user to enter username and password. After the user enters both username and password, it hashes the password and search the AMU file to verify both the user name and password. If the program verifies the username and password, it returns the message “Access Granted.” If the programcould not verify the username, it returns the message “Access Denied. You are not a registered user.” If the program verifies the username but not the password, it prompts the user to enter the password again. If the user enter the password three times incorrectly, the system locks the user account and gives this message. “You exceeded entering the allowablenumber of incorrect password. Your account is locked. Contact system administrator to unlock your account”
In: Computer Science
What are the key activities performed in the implementation phase and how are they connected in project management?
In: Computer Science
IN JAVA
Step 1 Develop the following interface: Interface Name: ImprovedStackInterface Access Modifier: public Methods Name: push Access modifier: public Parameters: item (data type T, parameterized type) Return type: void Throws: StackFullException Name: push Access modifier: public Parameters: item1 (data type T, parameterized type), item2 (data type T, parameterized type) Return type: void Throws: StackFullException Name: pop Access modifier: public Parameters: none Return type: void Throws: StackEmptyException Name: doublePop Access modifier: public Parameters: none Return type: void Throws: StackEmptyException Name: top Access modifier: public Parameters: none Return type: T (parameterized type) Throws: StackEmptyException Step 2 Develop the following class: Class Name: StackFullException Access Modifier: public Extends: Exception Constructors Name: StackFullException Access modifier: public Parameters: none (default constructor) Task: makes a call to the default constructor of its superclass Name: StackFullException Access modifier: public Parameters: message (datatype String) Task: makes a call to the constructor of its superclass by passing the parameter message to it Step 3 Develop the following class: Class Name: StackEmptyException Access Modifier: public Extends: Exception Constructors Name: StackEmptyException Access modifier: public Parameters: none (default constructor) Task: makes a call to the default constructor of its superclass Name: StackEmptyException Access modifier: public Parameters: message (datatype String) Task: makes a call to the constructor of its superclass by passing the parameter message to it Step 4 Develop the following class: Class Name: ImprovedArrayBasedStack Access Modifier: public Implements: ImprovedStackInterface Instance variables Name: top Access modifier: private Data type: int Name: stack Access modifier: private Data type: T[] (an array of parameterized type) Constructors Name: ImprovedArrayBasedStack Access modifier: public Parameters: none (default constructor) Task: sets the value of top to -1 sets the stack to refer to an array of Objects with 100 elements which are type cast to T[] Name: ImprovedArrayBasedStack Access modifier: public Parameters: size (data type int) Task: sets the value of top to -1 sets the stack to refer to an array of Objects with the number of elements equal to the size parameter which are type cast to T[] Methods Name: push Access modifier: public Parameters: item (data type T, parameterized type) Return type: void Throws: StackFullException Task: if the value of top is less than the length of the stack minus 1 then increase the value of top by 1 and place the item at the top of the stack, otherwise throw a StackFullException with the message "Not enough room for one item" Name: push Access modifier: public Parameters: item1 (data type T, parameterized type), item2 (data type T, parameterized type) Return type: void Throws: StackFullException Task: if the value of top is less than the length of the stack minus 2, then increase the value of top by 1 and place item1 at the top of the stack, then increase the value of top by 1 and place item2 at the top of the stack, otherwise throw a StackFullException with the message "Not enough room for two items" Name: pop Access modifier: public Parameters: none Return type: void Throws: StackEmptyException Task: if the value of top is greater than -1 then remove the item at the top of the stack by replacing it with null and decrease the value of top by 1, otherwise throw a StackEmptyException with the message "No item to remove" Name: doublePop Access modifier: public Parameters: none Return type: void Throws: StackEmptyException Task: if the value of top is greater than 0, then remove the item at the top of the stack by replacing it with null and decrease the value of top by 1, then remove the item at the top of the stack by replacing it with null and decrease the value of top by 1, otherwise throw a StackEmptyException with the message "There are less than two items in the stack" Name: top Access modifier: public Parameters: none Return type: T (parameterized type) Throws: StackEmptyException Task: if the value of top is greater than -1 then return the item at the top of the stack, otherwise throw a StackEmptyException with the message "Top attempted on an empty stack" Step 5 Develop a class with only a main method in it: import java.util.Scanner; public class ImprovedStackDemo { public static void main(String[] args) { /* Inside of this main method do the following: Create an object of the Scanner class that takes input from System.in and refer to this object as keyboard Create a reference to a ImprovedStackInterface called myImprovedStack and have it refer to a new object of the ImprovedArrayBasedStack type passing the value of 6 as an argument to the constructor Open a do/while loop Prompt the user to pick one of the following options: Press 1 to push one item onto the stack Press 2 to push two items onto the stack Press 3 to pop the top of stack Press 4 to pop the top of the stack twice Press 5 to look at the top of the stack Press 6 to end the program Save the user’s input into the option variable if the user picks option 1, prompt the user for what they would like to push onto the stack then save that in a variable called item Open a try block and inside that block call the push method by passing item as a parameter and then close the try block Open a catch block catching StackFullException e and inside this catch block print out the value of message stored in the exception else if the user picks option 2, prompt the user for what they would like to push onto the stack then save that in a variable called item1 Prompt the user for the second item that they would like to push onto the stack and save that in a variable called item2 Open a try block and inside that block call the push method by passing item1 and item 2 as parameters and then close the try block Open a catch block catching StackFullException e and inside this catch block print out the value of the message stored in the exception else if the user picks option 3, Open a try block and call the pop method and close the try block Open a catch block catching StackEmptyException e and inside this catch block print out the value of the message stored in the exception else if the user picks option 4, Open a try block and call the doublePop method and close the try block Open a catch block catching StackEmptyException e and inside this catch block print out the value of the message stored in the exception else if the user picks option 5, Open a try block and print the value returned by the top method and close the try block Open a catch block catching StackEmptyException e and inside this catch block print out the value of the message stored in the exception else if the user picks option 6, display Goodbye. else if the user picks any other option, display Error! close the do/while loop and make it so that it continues to run as long as the user does not pick option 6 */ } }
In: Computer Science
Describe a project, or process, where quality assurance may be one of the most costly activities? please explain
In: Computer Science
Write a program that takes a string from the user, identifies and counts all unique characters in that given string. You are bound to use only built-in string functions where necessary. For identification of unique characters and for counting of the characters make separate functions.
For character identification
Develop a program that takes a string argument, and returns an array containing all unique characters.
For character counting
Develop a program that takes an array returned from above function as an argument along with the given string and return an array containing the total count of each uniquely identified character present in the argument array.
In: Computer Science
1. Write a program that does the following. Write in Assembly Language program
Loads your student ID number into memory starting at location 0x2000 0100 a. DO NOT do any conversion on your ID number. If my ID number is 123456789, I should be able to read your ID in memory as 123456789 2. Loads the first six characters of your name, in ASSIC, in to memory right after your student ID. Total of 6 bytes. a. This means that you should NOT over write anything that you have already entered. 3. Load from memory location 0x0000 0000 into the registers a. R0 and R1 hold the 64 bits starting at 0x0000 0000 (Total of 2 Words, each of 32 bits) b. R2 holds the next byte (8 bits) data c. R3 holds the next half word (16 bits) d. R4 holds the next word (32 bits) 4. Use the debugger to test your program to make sure that it does what you think it does. Use Lab 1 to help you get started with this
In: Computer Science
1. Competitors
The results of a running competition are shown in the table below.
| Index | Name | Birthdate | Rank |
|---|---|---|---|
| 0 | Am, Erica | 1984. 05. 06. | 1 |
| 1 | Abnorm, Al | 1982. 09. 30. | 3 |
| 2 | Pri, Mary | 1988. 08. 25. | 2 |
| 3 | Duck, Ling | 1979. 06. 10. | 5 |
| 4 | Mac, Donald | 1992. 04. 05. | 4 |
Find an unfinished program below that contains the appropriate types and the above data in an array. Complete the program, step-by-step, according to the comments.
#include <stdio.h>
typedef struct Date {
int year, month, day;
} Date;
typedef struct Competitor {
char name[31];
Date birth;
int rank;
} Competitor;
void Date_print(Date d);
void Competitor_print(Competitor c);
int main() {
Competitor competitors[5] = {
{ "Am, Erica", {1984, 5, 6}, 1 },
{ "Abnorm, Al", {1982, 9, 30}, 3 },
{ "Pri, Mary", {1988, 8, 25}, 2 },
{ "Duck, Ling", {1979, 6, 10}, 5 },
{ "Mac, Donald", {1992, 4, 5}, 4 },
};
/* name of competitor 0 - printf %s */
/* rank of competitor 2 */
/* birth date of competitor 4, use the given function */
/* the first letter of the name of competitor 1 (a string is an array of characters) */
/* is competitor 1 among the best three? yes/no, may use ?: operator */
/* is competitor 4 faster than competitor 3? */
/* was competitor 1 born in the same year as competitor 2? */
/* complete the Competitor_print() function,
* then print all data of competitor 1 */
/* at last print all data of all competitors. */
return 0;
}
void Date_print(Date d) {
/* print year, month and day */
}
void Competitor_print(Competitor c) {
/* print all data of the competitor */
}
In: Computer Science
For a Car Rental System, do the following:
1. Decompose the system into 3 components
2. For each component, write 1-2 lines of Requirement
3. Draw Context Diagram based on the Requirements from #2 above.
4. Draw Level-0 diagram based on the Requirements from #2 above.
In: Computer Science
Compare and contrast Client/Server to Peer-to-Peer networks and which one you would consider to be best for a specific circumstance or context within a metropolitan area and why. Provide at least 3 examples.
In: Computer Science
Explain and provide examples for 5 ways RFIDs can be utilized in a Smart City. How does this differ from NFC technology? What are at least 3 advantages and disadvantages of NFC; explain reasoning with examples.
In: Computer Science
C++ Pie bakery
our bakery makes 8 kinds of pie, and receives orders for these pies from on-line buyers. The program you’ll write for this lab knows the price of each pie, so as each new order is received, it’s possible to know how much money the bakery should be receiving.
The program must read in lines of input which have two fields: a pie type and a quantity. With this, the program needs to update the quantity of that type of pie, adding the new order to those already received. You already have code that you’ve written for previous labs that uses getline() and splits the line read in into two separate parts: you get to re-use that here, since you have the same work to do – breaking an input string into two substrings, the first is the name of a kind of pie string and the second is the quantity int.
The program you are writing would be part of a larger system used by the bakery to track and schedule its baking. That’s good for you because it means that the input your program reads is guaranteed not to have bogus order numbers or pie types. A sample input line looks like:
raspberry 10
When the program reaches the end of input it prints out, for each type of pie, the quantity ordered and the total price of that number of those pies. After that it prints out the grand total of all orders (total number of pies, total price).
One problem you face is mapping pie types as strings (how you read them in) to the int index of the array element holding the struct for that pie type. For example, you might read in ”apple” and need to figure out that it’s in array element 3. You must use a function to handle this.
To make life a bit easier, you should initialize an array of struct with these pie types and prices:
peach lemon pumpkin blueberry apple raspberry strawberry cherry
$3.75 $4.50 $5.75 $4.25 $3.70 $6.35 $5.65 $5.20
Of course, you’ll need more than just these two fields in your
struct.
A sample run with 100 individual pie orders might produce output
like this.
Orders for peach: Orders for lemon: Orders for pumpkin: Orders for blueberry: Orders for apple: Orders for raspberry: Orders for strawberry: Orders for cherry:
115 value is $ 431.25 128 value is $ 576.00 75 value is $ 431.25 75 value is $ 318.75 71 value is $ 262.70 89 value is $ 565.15 122 value is $ 689.30 53 value is $ 275.60
Grand total: 728 pies for $3550.00
You can test your program with data you type in, or on a test data file you create.
In: Computer Science
python and mathematical solution
Assume that you design a new affine cipher, where you encrypt three letters at a time, where your alphabet is
{'A':0, 'B':1, 'C':2, 'D':3, 'E':4, 'F':5, 'G':6, 'H':7, 'I':8, 'J':9, 'K':10, 'L':11, 'M':12, 'N':13, 'O':14, 'P':15, 'Q':16, 'R':17, 'S':18, 'T':19, 'U':20, 'V':21, 'W':22, 'X':23, 'Y':24, 'Z':25, ' ':26, '.':27, ',': 28, '!': 29, '?':30}.
In other words, you group your plaintext message in trigrams (i.e., three-character words) and encrypt each trigram of the plaintext separately using this affine cipher. For example, if the first three letters of a plaintext is “THE” then it will be encoded as follows
THE -> 19×31×31 + 7×31 + 4 = 18480.
If the number of letters in the plaintext is not a multiple of three, you pad it with the letter “X” at the end. Determine the modulus and the size of the key space.
In: Computer Science
Explain the symbiotic relationship between search engines, webmasters, and users.
In: Computer Science
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int -*mySet: myType -MAX_VALUE = 500000 static const: int -LIMIT = 1000 static const: int +recursionSet() +recursionSet(const recursionSet&) +~recursionSet() +getSetLength() const: int +generateElements(int): void + getElement(int) const: myType +setElement(int, myType): void +readValue(const string) const: int +printSet() const: void +operator == (const recusrionSet&): bool +tak(myType, myType, myType) const: myType +printSeptenary(myType) const: void +squareRoot(myType, myType) const: myType -recSqRoot(myType, myType, myType) const: myType +recursiveSum() const: myType -rSum(int) const: myType +checkParentheses(string) const: bool -recChkPar(string, int, int) const: bool +recursiveInsertionSort(): void -recInsSort(int, int): void -insertInOrder(myType, int, int): voidYou may add additional private functions if needed (but, not for the recursive functions). Note, points will be deducted for especially poor style or inefficient coding. Function Descriptions • The recursionSet() constructor should set the length to 0 and mySet pointer to NULL. • The recusrsionSet(const recursionBucket&) copy constructor should create a new, deep copy from the passed object. • The ~recursionSet() destructor should delete the myType array, set the pointer to NULL, and set the size to 0. • The setElement(int, myValue) function should set an element in the class array at the given index location (over-writing any previous value). The function must include bounds checking. If an illegal index is provided, a error message should be displayed. • The getElement(int) should get and return an element from the passed index. This must include bounds checking. If an illegal index is provided, a error message should be displayed and a 0 returned. • The getSetLength() functions should return the current class array length. • The printSet(int) function should print the formatted class array with the passed number of values per line. Use the following output statement: cout << setw(5) << mySet[i] << " • "; Refer to the sample executions for formatting example. The readValue(string) function should prompt with the passed string and read a number from the user. The function should ensure that the value is 3 1 and £ MAX_VALUE. The function should handle invalid input (via a try/catch block). If an error occurs (out of range or invalid input) an appropriate message should be displayed and the user re- prompted. Example error messages include: cout << "readSetLenth: Sorry, too many " << "errors." << endl; cout << "readSetLenth: Error, value " << cnt << " not between 1 and " << numMax << "." << endl; • Note, three errors is acceptable, but a fourth error should end the function and return 0. The generateList(int) function should dynamically create the array and use the following casting for rand() to fill the array with random values. mySet[i] = static_cast(rand()%LIMIT); • • • The printSeptenary(myType) function should print the passed numeric argument in Septenary (base-7) format. Note, function must be written recursively. The recursiveSum() function will perform a recursive summation of the values in class data set and return the final sum. The function will call the private rSum(int) function (which is recursive). The rSum(int) function accepts the length of the data set and performs a recursive summation. The recursive summation is performed as follows: rSum ( position )= • { array[ 0] array[ position ] + rSum ( position−1) if position = 0 if position > 0 The tak(myType) function should recursively compute the Tak 1 function. The Tak function is defined as follows: tak ( x , y , z) = { z tak ( tak ( x−1, y , z) , tak ( y−1, z , x) , tak ( z −1, x , y ) ) 1 For more information, refer to: http://en.wikipedia.org/wiki/Tak_(function) if y≥ x if y < x• • The squareRoot(myType, myType) function will perform a recursive estimation of the square root of the passed value (first parameter) to the passed tolerance (second parameter). The function will call the private sqRoot(myType,myType,myType) function (which is recursive). The private recSqRoot(myType,myType,myType) function recursively determines an estimated square root. Assuming initially that a = x, the square root estimate can be determined as follows: recSqRoot ( x , a , epsilon) = • • • • • { 2 if ∣ a − x ∣ ≤ epsilon a 2 (a + x) sqRoot x , , epsilon 2 a ( ) if ∣ a 2 − x ∣ > epsilon The recursiveInsertionSort() function should sort the data set array using a recursive insertion sort. The recursiveInsertionSort() function should verify the length is valid and, if so, call the recInsSort() function to perform the recursive sorting (with the first element at 0 and the last element at length-1). The recInsSort(int, int) function should implement the recursive insertion sort. The arguments are the index of the first element and the index of the last element. If the first index is less than that last index, the recursive insertion sort algorithm is follows: ▪ Recursively sort all but the last element (i.e., last-1) ▪ Insert the last element in sorted order from first through last positions To support the insertion of the last element, the insertInOrder() function should be used. The insertInOrder(myType, int, int) function should recursively insert the passed element into the correction position. The arguments are the element, the starting index and the ending index (in that order). The function has 3 operations: ▪ If the element is greater than or equal to the last element in the sorted list (i.e., from first to last). If so, insert the element at the end of the sorted (i.e, mySet[last+1] = element). ▪ If the first is less than the last, insert the last element (i.e., mySet[last]) at the end of the sorted (i.e., mySet[last+1] = mySet[last]) and continue the insertion by recursively calling the insertInOrder() function with the element, first, and last-1 values. ▪ Otherwise, insert the last element (i.e., mySet[last]) at the end of the sorted (i.e., mySet[last+1] = mySet[last]) and set the last value (i.e., mySet[last]) to the passed element. The checkParentheses(string) function should determine if the parentheses in a passed string are correctly balanced. The function should call the private recChkPar(string, int, int) function (which is recursive) The recChkPar(string, int, int) function should determine if the parentheses in a string are correctly balanced. The arguments are the string, an index (initially 0), and a parenthesis level count (initially 0). The index is used to track the current character in the string. The general approach should be as follows: ◦ Identify base case or cases. ◦ Check the current character (i.e., index) for the following use cases: ▪ if str[index] == '(' → what to do then ▪ if str[index] == ')' → what to do then ▪ if str[index] == any other character → what to do then Note, for each case, increment the index and call function recursively.
In: Computer Science