A C program that going to accept a single command line arg and convert it to hexadecimal as an array of char that has 16 bits. The array should contain the hex of the int argument. Side note the command line arg is a valid signed int and the program should be able to convert negative numbers.
In: Computer Science
use a match almost once.
consider rhe following instance variable and method.
private int[]arr;
puplic int i(intx){
\\PRECOND
for (intk =arr.length-1;k>=0;k--){
\\LOOPINVAR
is(arr[k]<x)returnk;
}
\\POSTCOND
RETURN-1;
}
Let:int m=f(n)
1.assert(a!=null);
2.assert(a.length>0);
3.assert(true)
4.assert(false);
5. All values in positions 0 through m are less
than n.
6. All values in positions m+1 through
arr.lenght-1 are greater than or equal to n.
7.All the values in positions m+1 through
arr.lenght-1 are less then n.
8.The smallest value is at position m.
9.The largest value that is smaller that n is at
position m.
10.All values in positions k+1 through
arr.length-1 are greater than or equal to n.
11.All values in positions k though arr.length-1
are less than n.
12.all values in positions 0 through k are less
than n
13.int[] arr={3,9,3,5,8}
assertTrue(f(4)==2);
14.int[] arr={1,9,3,5,8}
assertTrue(f(4)==0);
The best Preconditions is ____
junit test for thr method that fails____
Best postondition____
junit test for the method that passes_____
Loop invariant_____
In: Computer Science
Write a Python script that will be used as a calculator to allow simple arithmetic computation of two input integer numbers.
Requirements:
a. The script should first allow the user to select if they want to add, subtract, multiply or divide two integer digits.
b. The script should pass the user inputs to a function using arguments for computation and the results return to the main part of the script.
c. The return value will be tested to determine if it is a positive number or a negative number.
In: Computer Science
Write a Python script that will collect 5 grades (float) from the student via input and obtain the average.
requirements:
a. Collect 5 floating grades from student
b. Obtain the average of the grades
In: Computer Science
Describe the differences between malware analysis methods –
Static vs Dynamic
▪
In: Computer Science
How do organizations get malware that needs to be analyzed?
▪ Pre-compromise – Email, web surfing interception, or honeypot collection
▪ Post-compromise - Incident response collection
In: Computer Science
I NEED THIS CODE FOR C++ IUSING SEMAPHORES PLEASE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#define THREADS 10 // Number of Thread
//bridge declared with array of character and integer
value
void Bridge(char array[], int value);
// Global Variable
int North = 1; //For North Number
int South = 1; //For South Number
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; // Setting Up
MUTEX for lock
//Thread for North farmer
void NorthFarmer(){
pthread_mutex_lock(&mutex1);
char array[5] = "North"; // North
printf("%s Tunbridge #%d farmer can cross the bridge\n", array,
North);
Bridge(array, North);
printf("%s Tunbridge #%d farmer has left the bridge\n\n", array,
North);
North++;
pthread_mutex_unlock(&mutex1);
pthread_exit(0);
}
//Thread for South farmer
void SouthFarmer(){
pthread_mutex_lock(&mutex1);
char array[5] = "South";
printf("%s Tunbridge #%d farmer can cross the bridge\n", array,
South);
Bridge(array, South);
printf("%s Tunbridge #%d farmer has left the bridge\n\n", array,
South);
South++;
pthread_mutex_unlock(&mutex1);
pthread_exit(0);
}
//void method for bridge
void Bridge(char array[], int value){
srand(time(NULL));
printf("%s Tunbridge #%d is traveling on the bridge...\n", array,
value);
int randomnumber = rand() % 4;
sleep(randomnumber);
}
//main method
int main(){
pthread_t North[THREADS]; // North Thread
pthread_t South[THREADS]; // South Thread
pthread_mutex_init(&mutex1,NULL);
for(int i = 0; i < THREADS; i++){
int CreateFirst = pthread_create(&North[i], NULL, NorthFarmer,
NULL);
int CreateSecond = pthread_create(&South[i], NULL, SouthFarmer,
NULL);
if(CreateFirst != 0 || CreateSecond != 0){
fprintf(stderr, "Thread Create Failed");
return 1;
}
}
for(int i = 0; i < THREADS; i++){
int JoinFirst = pthread_join(North[i],NULL);
int JoinSecond = pthread_join(South[i],NULL);
if(JoinFirst != 0 || JoinSecond != 0){
fprintf(stderr, "Join Failed");
return 1;
}
}
//destroy the mutex lock
pthread_mutex_destroy(&mutex1);
return 0;
}
In: Computer Science
I'm trying to ask a series of questions with validation in python.
example:
What is your name? (if valid name then continue to question 2)
What is your email? (if not valid then ask this question again, if valid then next question)
How old are you? (again, if invalid then ask again, if valid then next.
import re
def get_new_artwork():
name_regex = "^(?=.{2,40}$)[a-zA-Z]+(?:[-'\s][a-zA-Z]+)*$"
email_regex = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
while True:
name = input('Enter your name: ').title().strip()
if re.search(name_regex, name) is None:
print('Invalid name. ')
else:
email = input('Enter your email: ')
if re.search(email_regex, email) is None:
print('Invalid email. ')
else:
age = int(input('How old are you? '))
if age >=17:
print('Too young. ')
else:
print('user added. ')
break
return (name, email, age)
get_new_artwork()
In: Computer Science
Solve the the process scheduling problem using the round robin FCFS algorithm studied in assignment 7. The program will show the order of execution of the processing and will provide the average waiting time for the following scenarios:
a) Time quantum =1
b) Time Quantum=3
Use the table below to draw the Gantt Chart (Spread sheet or by hand).
Process ID | Arrival Time | Burst Time |
1 | 0 | 4 |
2 | 1 | 5 |
3 | 2 | 2 |
4 | 3 | 1 |
5 | 4 | 6 |
6 | 6 | 3 |
7 | 7 | 2 |
In: Computer Science
Illustrate, by example, how a C++ struct may be passed as a parameter by value or by reference. Also, show how it can be returned from a function. Be thorough in your example and explain your code.
In: Computer Science
CPP
Task: You are to write a class called Monomial, using filenames monomial.h and monomial.cpp, that will allow creation and handling of univariate monomials, as described below.
Monomial Description
Each monomial object has following properties:
Class Details
The single constructor for the Monomial class should have 2 parameters: an floating point coefficient value (optional, with a default value of 1.0); and an integer power value (optional, with a default value of 1). If the power value is less then 1, set the power to 1. The class will need to provide internal storage for any member data that must be kept track of.
There should be member functions GetCoefficient, and GetPower, which will return the monomial’s coefficient value, and monomial’s power value, respectively. The GetPower method should return integer results. The GetCoefficient function should return its result as a float.
There should be member functions SetPower, which will set the monomial’s power to the arbitrary positive value. If the parameter is not positive then set the power to the default value 1.
There should be member function Add, which adds the one monomial to the other. The parameter of this member function need to be a constant reference to the other monomial object. The monomials can only be added if they have the same power, otherwise error message must be printed. The result of the addition is saved in the caller object.
There should be two member functions Multiply (overrides), which each allow to multiply a monomial to a number and to another monomial. The first member function need to accept floating point parameter that is used to perform multiplication of the real number on the the monomial object. The second member function need to accept a constant reference to the other monomial object. Use monomials to coefficients and powers to perform their multiplication. The result of the multiplication is saved in the caller object.
There should be a member function called Exponent that perform exponentiation (raise to power) of the monomial to the specified power value. You only can raise monomial to the positive power, if the power parameter is not positive print error message. The result of the exponentiation is saved in the caller object.
A sample driver program (called monomial-driver.cpp) is provided. It uses objects of type Monomial and illustrates sample usage of the member functions.
Your class declaration and definition files must work with my main program from the test driver, as-is (do not change my program to make your code work!). You are encouraged to write your own driver routines to further test the functionality of your class, as well. Most questions about the required behavior of the class can be determined by carefully examining my driver program and the sample execution. Keep in mind, this is just a sample. Your class must meet the requirements listed above in the specification - not just satisfy this driver program. (For instance, I haven’t tested every illegal fill character in this driver program - I’ve just shown a sample). Your class will be tested with a larger set of calls than this driver program represents.
General Requirements
Test Driver:
// // driver.cpp -- driver program to demonstrate the behavior of // the Monomial class #include <iostream> #include "monomial.h" using namespace std; int main() { // create some monomial: x, 2x, 12.5x³, -3xâ¶ Monomial m1, m2( 2.0 ), m3( 12.5, -1 ), m4( -3.0 , 6); // display monomial cout << "Monomial `m1` has the coefficient " << m1.GetCoefficient() << " and power " << m1.GetPower() << ": "; m1.Print(); cout << "Monomial `m2` has the coefficient " << m2.GetCoefficient() << " and power " << m2.GetPower() << ": "; m2.Print(); cout << "Monomial `m3` has the coefficient " << m3.GetCoefficient() << " and power " << m3.GetPower() << ": "; m3.Print(); cout << "Monomial `m4` has the coefficient " << m4.GetCoefficient() << " and power " << m4.GetPower() << ": "; m4.Print(); // Change monomial power cout << "Monomial `m3` power wasn't changed: "; m3.SetPower(-1); m3.Print(); cout << "Monomial `m3` power was changed: "; m3.SetPower(3); m3.Print(); // can add monomials with the same powers cout << "Monomial addition" << endl; m1.Add(m2); cout << "x + 2x = "; m1.Print(); // cannot add monomials with different powers cout << "x³ + 12.5x³ = "; m2.Add(m3); // can multiply monomial to a number cout << "Monomial multiplication by a number" << endl; m2.Multiply(2.5); cout << "2x * 2.5 = "; m2.Print(); // can multiply monomials cout << "Monomial multiplication by a monomial" << endl; m3.Multiply(m4); cout << "12.5x³ * -3xâ¶ = "; m3.Print(); // can raise monomial to the power cout << "Monomial exponentiation" << endl; m4.Exponent(3); cout << "(-3xâ¶)³ = "; // -27x^18 m4.Print(); cout << "(3x)â° = "; // -27x^18 m1.Exponent(-10); return 0; }
Test Driver Output
Monomial `m1` has the coefficient 1 and power 1: 1x^1 Monomial `m2` has the coefficient 2 and power 1: 2x^1 Monomial `m3` has the coefficient 12.5 and power 1: 12.5x^1 Monomial `m4` has the coefficient -3 and power 6: -3x^6 Monomial `m3` power wasn't changed: 12.5x^1 Monomial `m3` power was changed: 12.5x^3 Monomial addition x + 2x = 3x^1 x³ + 12.5x³ = Cannot add monomials with different powers Monomial multiplication by a number 2x * 2.5 = 5x^1 Monomial multiplication by a monomial 12.5x³ * -3x⁶ = -37.5x^9 Monomial exponentiation (-3x⁶)³ = -27x^18 (3x)⁰ = Can raise only to a positive power
In: Computer Science
Consider a class ‘A’ with a method public static void show( ). A
class ‘Derived’ is the subclass of ‘A’.
Is it possible to define the same method public static void show( )
in the Derived class. Why give reasons? Is it run time
polymorphism? (0.5 Marks)
Is it possible to define the method public void show( ) (non static
method) in the Derived class. What will happen and why give
reasons?
In: Computer Science
<!DOCTYPE html>
<html>
<body>
<!-- replace the text below with your name!-->
<!-- -->
<!-- -->
<title> name </title>
<script>
//
// Write a function that calculates the amount of money a person
would earn over
// a period of years if his or her salary is one penny the first
day, two pennies
// the second day, and continues to double each day. The program
should ask the
// user for the number of years and call the function which will
return the total
// money earned in dollars and cents, not pennies. Assume there are
365 days
// in a year.
//
function totalEarned(years) {
/////////////////////////////////////////////////////////////////////////////////
// Insert your code between here and the next comment block. Do not
alter //
// any code in any other part of this file. //
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// Insert your code between here and the previous comment block. Do
not alter //
// any code in any other part of this file. //
/////////////////////////////////////////////////////////////////////////////////
}
var yearsWorked = parseInt(prompt('How many years will you work
for pennies a day? '));
alert('Over a total of ' + yearsWorked + ', you will have earned $'
+ totalEarned(yearsWorked));
</script>
</body>
</html>
In: Computer Science
On Lab 10 you did Chapter 8’s Programming Exercise 13, using the name Lab10TestScores and assuming that the class has ten students and five tests. Now let’s rewrite it to use dynamic arrays so that it will work for any number of students and any number of tests. Call this new program Lab11TestScores. Modify the program so that it asks the user to enter the number of students and the number of tests before it reads the data from the file named Lab11ScoresData.txt. (Two data files, Lab11ScoresData_5_3.txt and Lab11ScoresData_11_6.txt, are provided so you can use to test your program.). Let me know if you have questions. #include #include using namespace std; void readFile(string names[10], int scores[][5]) { ifstream in("Lab10ScoresData.txt"); for (int i = 0; i < 10; i++) { in >> names[i] >> scores[i][0] >> scores[i][1] >> scores[i][2] >> scores[i][3] >> scores[i][4]; } } void average(int scores[][5], float avg[], char grade[]) { int total; for (int i = 0; i < 10; i++) { total = 0; for (int j = 0; j < 5; j++) total += scores[i][j]; avg[i] = (float)total / (float)5; } for (int i = 0; i < 10; i++) { if (avg[i] >= 90) grade[i] = 'A'; if (avg[i] < 90 && avg[i] >= 80) grade[i] = 'B'; if (avg[i] < 80 && avg[i] >= 70) grade[i] = 'C'; if (avg[i] < 70 && avg[i] >= 60) grade[i] = 'D'; if (avg[i] < 60 && avg[i] >= 50) grade[i] = 'E'; if (avg[i] < 50) grade[i] = 'F'; } } void sortByName(string names[], float avg[], char grade[]) { for (int i = 0; i < 9; i++) { for (int j = i + 1; j < 10; j++) { if (names[i] > names[j]) { string n = names[i]; names[i] = names[j]; names[j] = n; float a = avg[i]; avg[i] = avg[j]; avg[j] = a; char g = grade[i]; grade[i] = grade[j]; grade[j] = g; } } } } void output(string names[], float avg[], char grade[]) { cout << "Name\tAverage\tGrade\n"; for (int i = 0; i < 10; i++) { cout << names[i] << "\t" << avg[i] << "\t" << grade[i] << endl; } } void countGrade(char grade[]) { int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0; cout << "\n\nGrade\tCount\n"; for (int i = 0; i < 10; i++) { if (grade[i] == 'A') a++; if (grade[i] == 'B') b++; if (grade[i] == 'C') c++; if (grade[i] == 'D') d++; if (grade[i] == 'E') e++; if (grade[i] == 'F') f++; } cout << "A\t" << a << endl; cout << "B\t" << b << endl; cout << "C\t" << c << endl; cout << "D\t" << d << endl; cout << "E\t" << e << endl; cout << "F\t" << f << endl; } int main() { string names[10]; int scores[10][5]; float avg[10]; char grade[10]; readFile(names, scores); average(scores, avg, grade); sortByName(names, avg, grade); output(names, avg, grade); countGrade(grade); system(" pause "); return 0; }
Lab11ScoresData_11_6.txt.
Johnson 85 83 77 91 76 99 Aniston 80 90 95 93 48 100 Cooper 78 81 11 90 73 54 Gupta 92 83 30 69 87 78 Blair 23 45 96 38 59 82 Clark 60 85 45 39 67 67 Kennedy 77 31 52 74 83 77 Bronson 93 94 89 77 97 80 Sunny 79 85 28 93 82 45 Smith 85 72 49 75 63 92 Groot 90 87 94 75 100 100
Lab11ScoresData_5_3.txt
Johnson 85 83 77 Aniston 80 90 95 Cooper 78 81 11 Gupta 92 83 30 Blair 23 45 96
In: Computer Science
Linked Lists
Problem 1
Implement a program that reads the following ages (type int) from
text file ages.txt and stores
them in a linked list:
16 18 22 24 15 31 27 19 13
Implement the class LinkedList along with any applicable member
functions (e.g. void
insert(int num)).
Perform the following actions on the list (if applicable, use
recursion):
1. Display the data in the list
2. Insert 18 at the front of the list
3. Insert 23 at the end of the list
4. Insert 25 after the number 24
5. Compute the average age
6. Sort the ages in ascending order
7. Determine how many people are 18 or older
Problem 2
Implement a program that reads the following data (two strings, one
double) from text file
balances.txt and stores it in a linked list:
John Miller 2508.13
Carolyn Spacer 188.54
Mark Lee 1816.82
Sophia Brown 3200.68
Jim Gomez 12068.34
Carlos Mendoza 783.41
Erica Robertson 2000.67
Implement the class LinkedList along with any applicable member
functions (e.g. void
moveToEnd(string fullName)).
Perform the following actions on the list:
1. Display the data in the list
2. Remove the person with the lowest balance
3. Display the name and balance of the person with the most
money
4. Display the average balance of people with a balance of $2,000
or more
5. Find Sophia Brown and move her to the end of the list (use
multipurpose helper
functions to make this easier)
In: Computer Science