In: Computer Science
C++ PLEASE
This will be a multi-part assignment. Later homework will expand upon what is developed in this assignment.
1. Create a class called MyComplex to represent complex numbers. Each part (Real and Imaginary parts) should be stored as a double. Data members should be private and you need to supply appropaiate accessor and mutator methods.
2. Supply a default constructor (both parts zero), a constructor that allows the real part to be set and a third constructor that allows both parts to be set.
3. Supply an insertion operator that will allow the value of a complex number to be printed. The output should look like: 2+3i, 1-4i, -2+0i, 0+5i for example.
4. Supply a complete program that exercises your class. (be sure you also exercise the accessor and mutator functions). You must supply a listing of your program and sample output.
In: Computer Science
3. Add mutex locks to tprog2.c to achieve synchronization, and screenshot the output tprog2.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h>
void* print_i(void *ptr) {
printf("1: I am \n"); sleep(1); printf("in i\n");
}
void* print_j(void *ptr) {
printf("2: I am \n"); sleep(1); printf("in j\n");
}
int main() {
pthread_t t1,t2;
int rc1 = pthread_create(&t1, NULL, print_i, NULL); int rc2 = pthread_create(&t2, NULL, print_j, NULL);
exit(0);
}
In: Computer Science
In Java: Initiate empty queue of strings and recreate .isempty, .size, .dequeue, .enqueue methods.
//You may not use the original methods of the stack api to answer. You may not add any more fields to the class.
import java.util.NoSuchElementException;
import edu.princeton.cs.algs4.Stack;
public class StringQueue {
//You may NOT add any more fields to this class.
private Stack stack1;
private Stack stack2;
/**
* Initialize an empty queue.
*/
public StringQueue() {
//TODO
}
/**
* Returns true if this queue is empty.
*
* @return {@code true} if this queue is empty; {@code
false} otherwise
*/
public boolean isEmpty() {
//TODO
}
/**
* Returns the number of items in this queue.
*
* @return the number of items in this queue
*/
public int size() {
// TODO
}
/**
* Adds the item to this queue.
*
* @param item the item to add
*/
public void enqueue(String item) {
// TODO
}
/**
* Removes and returns the item on this queue that was
least recently added.
*
* @return the item on this queue that was least
recently added
* @throws NoSuchElementException if the queue is
empty
*/
public String dequeue() throws NoSuchElementException
{
// TODO
}
}
Hints:
You will need to store enqueued items on one of the stacks.
However, when it comes time to dequeue, those items will be in the
wrong order, so use the second stack to reverse the order. Note
that once the items are in the second stack, they will come out of
the second stack in the correct order and you can still use the
first stack to store new items that are enqueued. You should not
keep moving the strings back and forth between the two stacks as
this will make your solution extremely inefficient. Each string
should be inserted into stack1 and most once and into stack2 at
most once.
I suggest you start with the very simple sequence: enqueue(“one”),
enqueuer(“two”), dequeue(), dequeue(). Of course, the String “one”
should come out first followed by the String “two”. Once you have
that working, start testing your code with more complex sequences
and fixing any use cases you missed in your original attempt at a
solution. For example, make sure to at least try the seuquence
enqueue(“one”), enqueuer(“two”), dequeue(), enqueue(“three”),
dequeue(), dequeue().
In: Computer Science
2.explain the need and rational of small scale industry list out the different steps to start a ssi.(50marks)
Need own answer and no internet answers r else i il downvote nd report to chegg.Even a single is wrong i il downvote.its 50marks question so no short answer minimum 10page answer required and own answer r else i il downvote.
Note:Minimum 10page answer and no plagarism r else i il downvote and report to chegg.Minimum 10 to 15page answer required r else dnt attempt.strictly no internet answer n no plagarism.
its 50marks question so i il stricly review nd report
In: Computer Science
Use case Names: Record a Ticket
Scenario: Officer Issues a Ticket
Triggering Event: Traffic Ticket
Description: The Officer provides the Clerk with the ticket. And then the ticket information is verified by the clerk. First he/she enters the Officers badge number and next enters the drivers license number to verify their information.
Action: Clerk
Stakeholders: Manager, Officer
Precondition: The officer and driver must exist.
Postcondition: The ticket must exit and be associated with the Officer, the driver, and the Court.
Exception Conditions: Officer not found, Driver not found.
Flow of Event:
Action |
System |
1. Officer enters offices badge number. |
System reads officer information and displays name. |
2. Officer enters drivers license number. |
System reads the drivers information and displays the drivers name and address. |
3. Clerk enters ticket information. |
System displays ticker and drivers information. |
Task
In: Computer Science
Question 1 |
|
Refer to the operations below: |
|
Add (10 + 5) |
|
Add (4+8) |
|
Add (7*2) |
|
Add (90 – 3) |
|
Print list |
|
Print peek |
|
Remove an item from the list |
|
Print list |
|
1.1 Implement the operations above into a Queue structure called q1. |
(10) |
1.2 Implement the operations above into a Stack structure called s1. |
(10 |
Guidelines: Please take note!
(a) Name your program Question1_1 for the queue structure and Question1_2 for the stack structure
(b) The Java Programmer is required to include screenshots from a JGrasp IDE which displays their commented code and the output and also indicates their laptop date and time of code execution, the screenshot of the code needs to be error-free and must not produce any logic errors!
In: Computer Science
function varargout = untitled(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
function untitled_OpeningFcn(hObject, eventdata, handles,
varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = untitled_OutputFcn(hObject, eventdata,
handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
handles.img2=uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image
Files';...
'*.*','All Files' },'G:\dipproject')
img=handles.img2;
axes(handles.axes1)
imshow(img);
guidata(hObject, handles);
function pushbutton3_Callback(hObject, eventdata, handles)
img=handles.img2;
img=imread(img)
bw=im2bw(img,0.7);
label=bwlabel(bw);
stats=regionprops(label,'Solidity','Area');
density=[stats.Solidity];
area=[stats.Area];
high_dense_area=density>0.5;
max_area=max(area(high_dense_area));
tumor_label=find(area==max_area);
tumor=ismember(label,tumor_label);
se=strel('square',5);
tumor=imdilate(tumor,se);
axes(handles.axes2)
imshow(tumor,[]);
guidata(hObject, handles);
function pushbutton4_Callback(hObject, eventdata, handles)
img=handles.img2;
img=imread(img)
contents=get(hObject,'value')
bw=im2bw(img,0.7);
label=bwlabel(bw);
stats=regionprops(label,'Solidity','Area');
density=[stats.Solidity];
area=[stats.Area];
high_dense_area=density>0.5;
max_area=max(area(high_dense_area));
tumor_label=find(area==max_area);
tumor=ismember(label,tumor_label);
se=strel('square',5);
tumor=imdilate(tumor,se);
[B,L]=bwboundaries(tumor,'noholes');
axes(handles.axes3)
imshow(img,[]);
hold on
for i=1:length(B)
plot(B{i}(:,2),B{i}(:,1), 'y' ,'linewidth',1.45);
end
guidata(hObject, handles);
function pushbutton5_Callback(hObject, eventdata, handles)
clc
clear all;
close all;
Please explain this code step by step matlab program
In: Computer Science
Consider the following classes:
public class Clock extends Bear { public void method3() { System.out.println("Clock 3"); } } public class Lamp extends Can { public void method1() { System.out.println("Lamp 1"); } public void method3() { System.out.println("Lamp 3"); } } public class Bear extends Can { public void method1() { System.out.println("Bear 1"); } public void method3() { System.out.println("Bear 3"); super.method3(); } } public class Can { public void method2() { System.out.println("Can 2"); method3(); } public void method3() { System.out.println("Can 3"); } }
---and that the following variables are defined:---
Object var1 = new Bear(); Can var2 = new Can(); Can var3 = new Lamp(); Bear var4 = new Clock(); Object var5 = new Can(); Can var6 = new Clock();
For each statement below , match the output produced in the right-hand column by the statement in the left-hand column. If the statement produces more than one line of output, the line breaks are indicated with slashes as in "a/b/c" to indicate three lines of output with "a" followed by "b" followed by "c". If the statement causes an error, choose in the right-hand column with either the phrase "compiler error" or "runtime error" to indicate when the error would be detected.
Note: Multiple statements can have the same output (ex: Compiler Error or Runtime Error)
var1.method2();
var2.method2();
var3.method2();
var4.method2();
var5.method2();
var1.method3();
var2.method3();
var3.method3();
var6.method3();
((Lamp)var6).method1();
((Can)var1).method1();
((Can)var1).method2();
((Bear)var1).method3();
((Clock)var1).method1();
---The choices for all methods are:---
Clock 3
Can 2/Can 3
Runtime Error
Compiler Error
Can 2/Bear 2/Can 3
Can 2/Clocl 3
Can 3
Bear3/Can 3
In: Computer Science
Using PHP, design a function that given a Roman numeral (Wikipedia link.), in input, is able to compute the modern Hindu–Arabic numeral (wikipedia link), system representation (aka, 0123456789).
For example:
Input | Output |
VI | 6 |
IV | 4 |
MCMXC | 1990 |
IX | 9 |
In: Computer Science
Input Format
4 1 2 3 4
Constraints
there will be no more than 50 input numbers.
Output Format
Odd: 2 Even: 2 Divisible by 7: 0 Average: 250
Sample Input 0
4 1 2 3 4
Sample Output 0
Odd: 2 Even: 2 Divisible by 7: 0 Average: 250
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bufferedReader.readLine().trim());
String[] arrTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
List<Integer> arr = new ArrayList<>();
for (int i = 0; i < n; i++) {
int arrItem = Integer.parseInt(arrTemp[i]);
arr.add(arrItem);
}
// You now have an array of integers called arr. You should process the array to achieve the results.
// note that you can refer to items in arr using standard Java array notation
// arr[0] will give you the item at location 0 in this array
// Write your code here
bufferedReader.close();
}
}
In: Computer Science
JAVA Programming
(Convert decimals to fractions)
Write a program that prompts the user to enter a decimal number and
displays the number in a fraction.
Hint: read the decimal number as a string, extract the integer part
and fractional part from the string, and use the Rational class in
LiveExample 13.13 to obtain a rational number for the decimal
number. Use the template at
https://liveexample.pearsoncmg.com/test/Exercise13_19.txt
for your code.
Sample Run 1
Enter a decimal number: 3.25
The fraction number is 13/4
Sample Run 2
Enter a decimal number: -0.45452
The fraction number is -11363/25000
The output must be similar to the Sample Runs ( Enter a decimal number: etc.)
Class Name MUST be Exercise13_19
If you get a logical or runtime error, please refer
https://liveexample.pearsoncmg.com/faq.html.
RATIONAL CLASS:
/* You have to use the following template to submit to Revel. Note: To test the code using the CheckExerciseTool, you will submit entire code. To submit your code to Revel, you must only submit the code enclosed between // BEGIN REVEL SUBMISSION // END REVEL SUBMISSION */ import java.util.Scanner; // BEGIN REVEL SUBMISSION public class Exercise13_19 { public static void main(String[] args) { // Write your code } } // END REVEL SUBMISSION // Copy from the book class Rational extends Number implements Comparable<Rational> { // Data fields for numerator and denominator private long numerator = 0; private long denominator = 1; /** Construct a rational with default properties */ public Rational() { this(0, 1); } /** Construct a rational with specified numerator and denominator */ public Rational(long numerator, long denominator) { long gcd = gcd(numerator, denominator); this.numerator = (denominator > 0 ? 1 : -1) * numerator / gcd; this.denominator = Math.abs(denominator) / gcd; } /** Find GCD of two numbers */ private static long gcd(long n, long d) { long n1 = Math.abs(n); long n2 = Math.abs(d); int gcd = 1; for (int k = 1; k <= n1 && k <= n2; k++) { if (n1 % k == 0 && n2 % k == 0) gcd = k; } return gcd; } /** Return numerator */ public long getNumerator() { return numerator; } /** Return denominator */ public long getDenominator() { return denominator; } /** Add a rational number to this rational */ public Rational add(Rational secondRational) { long n = numerator * secondRational.getDenominator() + denominator * secondRational.getNumerator(); long d = denominator * secondRational.getDenominator(); return new Rational(n, d); } /** Subtract a rational number from this rational */ public Rational subtract(Rational secondRational) { long n = numerator * secondRational.getDenominator() - denominator * secondRational.getNumerator(); long d = denominator * secondRational.getDenominator(); return new Rational(n, d); } /** Multiply a rational number to this rational */ public Rational multiply(Rational secondRational) { long n = numerator * secondRational.getNumerator(); long d = denominator * secondRational.getDenominator(); return new Rational(n, d); } /** Divide a rational number from this rational */ public Rational divide(Rational secondRational) { long n = numerator * secondRational.getDenominator(); long d = denominator * secondRational.numerator; return new Rational(n, d); } @Override public String toString() { if (denominator == 1) return numerator + ""; else return numerator + "/" + denominator; } @Override // Override the equals method in the Object class public boolean equals(Object other) { if ((this.subtract((Rational)(other))).getNumerator() == 0) return true; else return false; } @Override // Implement the abstract intValue method in Number public int intValue() { return (int)doubleValue(); } @Override // Implement the abstract floatValue method in Number public float floatValue() { return (float)doubleValue(); } @Override // Implement the doubleValue method in Number public double doubleValue() { return numerator * 1.0 / denominator; } @Override // Implement the abstract longValue method in Number public long longValue() { return (long)doubleValue(); } @Override // Implement the compareTo method in Comparable public int compareTo(Rational o) { if (this.subtract(o).getNumerator() > 0) return 1; else if (this.subtract(o).getNumerator() < 0) return -1; else return 0; } }
In: Computer Science
Create an example schema representing Edgar Rice Burroughs published works starting with him as an author and representing most of the metadata present in the following site/list of books.
http://www.gutenberg.org/ebooks/author/48 (Links to an external site.)
You need to include 5 books in your example schemas.
Create a JSON schema representing 5 of an author (Edgar Rice Burroughs) works.
In: Computer Science
JAVA
Start with the SelectionSort class in the zip file attached to this item. Keep the name SelectionSort, and add a main method to it.
In your submission write some text describing the relationship between the number of comparisons of the various values of NUM_ELEMENTS. For example, what do we find if we divide the number of comparisons for 2000 elements by the number of comparisons for 1000 elements? What do we find if we divide the number of comparisons for 4000 elements by the number of comparisons for 2000 elements?
SELECTION SORT FILE MUST USE THIS IN PROGRAM!!! PLEASE
public class SelectionSort {
/** The method for sorting the numbers */
public static void selectionSort(double[] list) {
for (int i = 0; i < list.length - 1; i++) {
// Find the minimum in the list[i..list.length-1]
double currentMin = list[i];
int currentMinIndex = i;
for (int j = i + 1; j < list.length; j++) {
if (currentMin > list[j]) {
currentMin = list[j];
currentMinIndex = j;
}
}
// Swap list[i] with list[currentMinIndex] if
necessary;
if (currentMinIndex != i) {
list[currentMinIndex] = list[i];
list[i] = currentMin;
}
}
}
}
In: Computer Science
The input file, “input.txt” is called parse Text.txt
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate — we can not consecrate — we can not hallow — this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us — that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion — that we here highly resolve that these dead shall not have died in vain — that this nation, under God, shall have a new birth of freedom — and that government of the people, by the people, for the people, shall not perish from the earth.
In: Computer Science