Write a MARIE assembly language program that will read an “array” of positive decimal values stored in memory and output the smallest value. Use variable addr to store the location of the first data item. Use variable length to store the number of items in your array.
Your code should be organized such that adding an additional array item would only involve adding the data line (ie. 021 dec 400) and updating the length variable (ie. length, dec 5). You can assume there will be at least one data value.
Use comments throughout your program. Save your program as h9part1.mas and upload to our course web site.
/sample data, note: addresses will vary depending on your implementation
015 addr, hex 017
016 length, dec 4
017 dec 100
018 dec 200
019 dec 50
020 dec 300
In: Computer Science
Java Programming Problem:
Define a generic method called checkOrder() that checks if four items are in ascending, neither, or descending order. The method should return -1 if the items are in ascending order, 0 if the items are unordered, and 1 if the items are in descending order.
The program reads four items from input and outputs if the items are ordered. The items can be different types, including integers, Strings, characters, or doubles.
Ex. If the input is:
bat hat mat sat 63.2 96.5 100.1 123.5
the output is:
Order: -1 Order: -1
The following is the current code for the problem:
import java.util.Scanner;
public class WhatOrder {
// TODO: Define a generic method called checkOrder() that
// takes in four variables of generic type as arguments.
// The return type of the method is integer
// Check the order of the input: return -1 for ascending,
// 0 for neither, 1 for descending
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// Check order of four strings
System.out.println("Order: " + checkOrder(scnr.next(), scnr.next(),
scnr.next(), scnr.next()));
// Check order of four doubles
System.out.println("Order: " + checkOrder(scnr.nextDouble(),
scnr.nextDouble(), scnr.nextDouble(), scnr.nextDouble()));
}
}
In: Computer Science
Write a C++ program to score the paper-rock-scissor game. Each of two players (player1 and player2) input a character which could be either ‘P’, ‘R’, or ‘S’ (in uppercase or lowercase). For any other input character should display a message “Invalid input”. The program then announces who is the winner as well as the basis for determining the winner which could be one of the following: “Paper covers rock”, “Rock breaks scissors”, “Scissors cut paper”, or “Nobody wins”. (Use switch statement)
Please do not add up the scores just have a simple quick game and then I would have to reset the program to play again
In: Computer Science
VISUAL BASIC (VB.NET)1. Create a Sub Procedure with a
name of your choice and in the procedure, declare a
2-Dimensinal (2-D) array that can store 15 Integer numbers. Then
implement a
nested loop that will be used to store any 15 Integer numbers into
the 2-D array at
runtime (an interactive program).
The implementation will be such that the program cannot terminate
unless all the
inputs provided are integers (user input validation). If you
provide an invalid input,
you should be asked to “Try again”. Make sure also to print out all
valid inputs
respectively, after the point of insertion.
Note – The Procedure you created should be called in the Main
Procedure to run it.
In: Computer Science
Please paraphrase this c code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void sortGrades(int arr[], int size, int status, char
names[][20]);
void printer(int grades[], int size, char names[][20]);
void sortNames(char arr[][20], int size, int status, int
grades[]);
void nameSearch(int grades[], int size, char names[][20]);
void numSearch(int grades[], int size, char names[][20]);
int main()
{
int i;
int size;
int option;
do
{
printf("\n\nInput Number of Students or 0 to exit : ");
scanf("%d", &size);
if (size == 0)
{
break;
}
char names[size][20];
int grades[size];
for (i = 0; i < size; i++)
{
printf("\nEnter the Name of Student %d : ", i + 1);
scanf("%s", &names[i]);
printf("Enter the Grades of Student %d : ", i + 1);
scanf("%d", &grades[i]);
}
do
{
printf("\n\nEnter\n1 for sort by Name(A-Z)\n2 for sort by
Name(Z-A)\n3 for sort by Grades(Ascending)\n4 for sort by
Grades(Descending)\n5 for search by Name\n6 for search by Grade's
limit\n0 to re enter data\n");
scanf("%d", &option);
switch (option)
{
case 1:
sortNames(names, size, 1, grades);
printer(grades, size, names);
break;
case 2:
sortNames(names, size, 0, grades);
printer(grades, size, names);
break;
case 3:
sortGrades(grades, size, 0, names);
printer(grades, size, names);
break;
case 4:
sortGrades(grades, size, 1, names);
printer(grades, size, names);
break;
case 5:
nameSearch(grades, size, names);
break;
case 6:
numSearch(grades, size, names);
break;
default:
break;
}
} while (option != 0);
} while (size != 0);
return 0;
}
void sortGrades(int arr[], int size, int status, char
names[][20])
{
int i, j; /*counter*/
int temp;
char temp2[100];
for (j = 0; j < size - 1; j++)
/*outer for loop to repeat to repeat inner loop without the largest
number selected before*/
{
for (i = 0; i < size - 1 - j; i++) /*inner for loop to swap the
largest number to the end*/
if (status == 0)
{
if (arr[i] < arr[i + 1])
{
// swapping using temp
temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
strcpy(temp2, names[i]);
strcpy(names[i], names[i + 1]);
strcpy(names[i + 1], temp2);
}
}
else
{
if (arr[i] > arr[i + 1])
{
// swapping using temp
temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
strcpy(temp2, names[i]);
strcpy(names[i], names[i + 1]);
strcpy(names[i + 1], temp2);
}
}
}
}
void sortNames(char arr[][20], int size, int status, int
grades[])
{
int i, j; /*counter*/
char temp[100]; /*temporary value for swap*/
int temp2;
for (j = 0; j < size - 1; j++)
/*outer for loop to repeat to repeat inner loop without the largest
number selected before*/
{
for (i = 0; i < size - 1 - j; i++) /*inner for loop to swap the
largest number to the end*/
if (status == 0)
{
if (strcmp(arr[i], arr[i + 1]) < 0)
{
// swapping using temp
strcpy(temp, arr[i]);
strcpy(arr[i], arr[i + 1]);
strcpy(arr[i + 1], temp);
temp2 = grades[i];
grades[i] = grades[i + 1];
grades[i + 1] = temp2;
}
}
else
{
if (strcmp(arr[i], arr[i + 1]) > 0)
{
// swapping using temp
strcpy(temp, arr[i]);
strcpy(arr[i], arr[i + 1]);
strcpy(arr[i + 1], temp);
temp2 = grades[i];
grades[i] = grades[i + 1];
grades[i + 1] = temp2;
}
}
}
}
void nameSearch(int grades[], int size, char names[][20])
{
int i;
char key[20];
int fail = 0;
printf("\nInput a Name that you want to find : ");
scanf("%s", &key);
for (i = 0; i < size; i++)
{
if (strcmp(names[i], key) == 0)
{
printf("\nMatch Found\nName : %s\nGrade : %d\nIndex Number : %d",
names[i], grades[i], i);
fail++;
}
}
if (fail == 0)
{
printf("\nMatch NOT Found");
}
}
void numSearch(int grades[], int size, char names[][20])
{
int j; /*counter*/
int key, condition, option;
printf("Enter a grade as limit/pivot to filter data : ");
scanf("%d", &key);
printf("Enter condition:\n1 for Greater than %d\n2 for Less than
%d\n", key, key);
scanf("%d", &option);
printf(" Name");
printf(" grades\n");
for (j = 0; j < size; j++)
{
switch (option)
{
case 1:
if (grades[j] > key)
{
printf("%10s", names[j]);
printf("%10d\n", grades[j]);
}
break;
case 2:
if (grades[j] < key)
{
printf("%10s", names[j]);
printf("%10d\n", grades[j]);
}
break;
default:
break;
}
}
}
void printer(int grades[], int size, char names[][20])
{
int j; /*counter*/
printf(" Name");
printf(" grades\n");
for (j = 0; j < size; j++)
{
printf("%10s", names[j]);
printf("%10d\n", grades[j]);
} /* for loop to print all of reversed array content*/
}
In: Computer Science
A complex number is a number with two components, namely, the real part (rel) and the imaginary part (img). For example the complex number (a+bi) has a as the real part and b as the imaginary part. In developing such a class, assume that both of the real and imaginary parts to be floats. The symbol i represent . A declaration for the Complex class is presented next.
class Complex {
public:
Complex (float r = 0.0, float g= 0.0);
Complex (const Complex & c); //The copy
constructor
void print( ) const; // Print out the class data
Complex & negate ( ); // Multiplies the data members of a
complex object by a
// negative one.
Complex addComplex (const Complex & b);
// add two complex numbers, the calling
//object and b and return a new complex //one
Complex subComplex (const Complex &b);
// subtract two complex numbers, the
// calling object and b and return a new
// complex one
Complex multipComplex ( const Complex &c) const; // multiply
two complex
// numbers and return a complex one
Complex assginComplex ( const Complex & c); // assign one
complex number to
// another one and return the result in a complex object.
bool isEqual (const Complex & c) const; //compares one complex
number to
// another and returns a Boolean value
private:
float rel;
float img;
};
Implement and test the class Complex. Write a driver program to
test your Complex class. Instantiate several Complex objects. Test
that all your member functions work properly.
Hint
• Addition of two complex numbers: (a+bi) +(c+di) =
(a+c) + (b+d) i
• Subtraction: (a+bi) (c+di) = (a-c) + (b-d) i
• Multiplication: (a+bi) * (c+di) = (ac-bd) + (ad+bc)
i
A sample run is given below:
Please enter the first complex number C1(r,img) ; 1 -5
Please enter the second complex number C2(r,img) ; 2 11
Testing the copy constructor C3= C2 = 2+11i
Testing the negate function C4 = C3.negate() = -2 -11i
Testing the assign function C5 = C3.assignComplex(C4) = -2 -11i
Testing the isEqual function C4.isEqual(C5) = 1
Testing the Add Complex function C6 = C1.addComplex(C2) = 3+6i
Testing the Sub Complex function C7 = C1.subComplex(C2) = -1 -16i
Testing the multiply Complex function C8 = C1.multipComplex(C2) = 57+1i
In: Computer Science
THIS is to be done in python!
Splitting the Bill- An exercise in input validation Write a python program called splitBill.py that works as follows:
• (10 points) Allow the user to input a bill amount, a tip percent, and the number of people in their party. o Input validation: Make sure to validate the input data. Allow the user to reenter inputs until they enter values which are valid.
▪ Make it easy on the user: To leave a 20% tip, the user should just enter 20. The tip amount should be a number between 1 and 50.
▪ The bill amount should be some numeric value between 1 and 5000.
▪ The number of people should be between 1 and 20. o Your program must follow the design of the BMI program discussed in lecture.
▪ It must have (a version) of the following functions: getNumber, isInputValid, getValidNumberInput, and main as in BMI. • (5 points) Output the amount in dollars each person in the party should pay, assuming they want to split the cost evenly.
o Round the output to at most 2 decimal places. (Search for python’s round() which is not discussed in the book)
o Put a $ sign in front of the output
. o Create a new function getSplitAmount that serves as the brains of your program and returns the amount each person in the party owes. This function is the brains of this program similar to how the getBMICategory is the brains in the BMI program.
• (10 pts) Testing: Write tester functions for the isInputValid and getSplitAmount functions.
• (3 pts) Comments: Write a comment for the getSplitAmount function Here are some examples of how your program should work when all inputs are valid. The highlighted parts were typed by the user. Bill: 100 Tip percent: 20 Number of people: 6 Each person pays: $20.0 Bill: 27.50 Tip percent: 10 Number of people: 2 Each person pays: $15.12
Here are some examples of how your program should work when all inputs are valid.
The highlighted parts were typed by the user.
Bill: 100
Tip percent: 20
Number of people: 6
Each person pays: $20.0
Bill: 27.50 Tip percent: 10
Number of people: 2
Each person pays: $15.12
In: Computer Science
Write a complete java program that Define a class named sample containing:
Please enter two numbers to divide: 10 Hi
You entered wrong input. Try again.
Please enter two numbers to divide: 15 0
Division could not be completed.
Enter 5 double numbers: 2.5 3.1 5.0 9.3 10.0
Which element you want to print? (Choose a number between 0-4): 7
Wrong choice. Try again.
Which element you want to print? (Choose a number between 0-4): 3
The element in position 3 = 9.3
Thank you for using this program.
In: Computer Science
IN JAVA PLEASE
Implement a recursive approach to showing all the teams that can be created from a group (n things taken k at a time). Write the recursive showTeams()method and a main() method to prompt the user for the group size and the team size to provide arguments for showTeam(), which then displays all the possible combinations.
In: Computer Science
As employer are in a shift to more cloud computing and cloud storage, what is the effect to our expectation of privacy?
Include dangers to users of social media and What remedies are available to victims and how do these differ from remedies victims of traditional crimes and torts?
In: Computer Science
complete the public T removeRandom(), public SetADT<T> union(SetADT<T> set), and the incomplete part in the arraysettester
arrayset.java
package arraysetpackage;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Random;
public class ArraySet<T> implements SetADT<T>
{
private static final int DEFAULT_SIZE = 20;
private int count;
private T[] setValues;
private Random rand;
public ArraySet (){
this(DEFAULT_SIZE);
} // end of constructor
public ArraySet (int size){
count = 0;
setValues = (T[]) new
Object[size];
rand = new Random();
} // end of constructor
public void add(T element) {
if (contains(element))
return;
if (count == setValues.length)
{
T[] temp = (T[])
new Object[setValues.length*2];
for (int i = 0;
i < setValues.length; i++) {
temp[i] = setValues[i];
}
setValues =
temp;
}
setValues[count] = element;
count++;
}
public void addAll(SetADT<T> set) {
Iterator<T> iter =
set.iterator();
while (iter.hasNext()){
System.out.println(iter.next());
}
// finish: this method adds all of
the input sets elements to this array
}
public boolean contains(T target) {
for (int i = 0; i < count; i++
)
if
(setValues[i].equals(target))
return true;
return false;
}
public String toString () {
String toReturn = "[";
for (int i = 0; i < count; i++)
{
toReturn +=
setValues[i] + " ";
}
toReturn +="]";
return toReturn;
}
public boolean equals(SetADT<T> set) {
// finish: tests to see if this set
and the input set have exactly the same
// elements
return false; // this is just
generic, you need to change the return
}
public boolean isEmpty() {
return count==0;
}
public Iterator<T> iterator() {
return new
ArraySetIterator<T>(setValues,count);
}
public T remove(T element) {
for (int i = 0; i < count; i++ )
{
if
(setValues[i].equals(element)) {
T toReturn = setValues[i];
setValues[i] = setValues[count-1];
count--;
return toReturn;
}
}
throw new
NoSuchElementException("not present");
}
public T removeRandom() {
// finish: remove and return a
random element. you will use the
// local rand object
return null; // this is just
generic, you need to change the return
}
public int size() {
return count;
}
public SetADT<T> union(SetADT<T> set)
{
// finish: a new set is created and
returned. This new set will
// contain all of elements from
this set and the input parameter set
return null; // this is just
generic, you need to change the return
}
}
arraysetester.java:
package arraysetpackage;
import java.util.Iterator;
public class ArraySetTester {
public static void main(String[] args) {
SetADT <String> mySet = new
ArraySet<String>();
for (int i = 0; i < 12;
i++)
mySet.add(new
String("apple"+i));
System.out.println(mySet);
System.out.println("mysize =
"+mySet.size()+ " [expect 12]");
mySet.add(new String
("apple0"));
System.out.println("mysize =
"+mySet.size()+ " [expect 12]");
System.out.println("contains 11? =
"+mySet.contains(new String("11")));
System.out.println("contains
apple11? = "+mySet.contains(new String("apple11")));
try {
String
removedItem = mySet.remove("apple7");
System.out.println(mySet);
System.out.println(removedItem+ " was removed");
} catch (Exception e) {
System.out.println("item not found, can't remove");
}
try {
String
removedItem = mySet.remove("apple17");
System.out.println(mySet);
System.out.println(removedItem+ " was removed");
} catch (Exception e) {
System.out.println("item not found, can't remove");
}
Iterator<String> iter =
mySet.iterator();
while (iter.hasNext()){
System.out.println(iter.next());
}
SetADT <String> mySet2 = new ArraySet<String>();
for (int i = 0; i < 12;
i++)
mySet2.add(new
String("orange"+i));
System.out.println(mySet2);
// add code here to test methods
you finish in ArraySet
// after you complete the existing
methods, do the Case Study
// Approach 1 will be here in the
main
// Approach 2 will be here in
ArraySetTester, but you will
// create a local static method
that you will call from the main
// Approach 3 will start with
uncommenting the prototype in SetADT
// and then creating the method in
ArraySet. Finally you will write
// code here to test the new
method
}
}
arraysetiterator.java
package arraysetpackage;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class ArraySetIterator <T> implements Iterator
<T> {
private int position; //Always points to the next
value
private T [] values;
private int count;
public ArraySetIterator (T [] theValues, int aCount)
{
position = 0;
values = theValues;
count = aCount;
}
public boolean hasNext() {
return position < count;
}
public T next() {
if (position >= count)
throw new
NoSuchElementException("Past " + count + " elements");
position++;
return values[position - 1];
}
public void remove() {
throw new
UnsupportedOperationException("No
remove for ArraySet");
}
}
setadt.java
package arraysetpackage;
import java.util.Iterator;
public interface SetADT<T> {
public void add (T element); //Adds one element to
this set, ignoring duplicates
public void addAll (SetADT<T> set); //Adds all
elements in the parameter to this set,
// ignoring duplicates
public T removeRandom (); //Removes and returns a
random element from this set
public T remove (T element); //Removes and returns the
specified element from this set
public SetADT<T> union (SetADT<T> set);
//Returns the union of this set and the
// parameter
public boolean contains (T target); //Returns true if
this set contains the parameter
//public boolean contains(SetADT<T> Set); //
Returns true if this set contains the parameter
public boolean equals (SetADT<T> set); //Returns
true if this set and the parameter
//contain exactly same elements
public boolean isEmpty(); //Returns true if this set
contains no elements
public int size(); //Returns the number of elements in
this set
public Iterator<T> iterator(); //Returns an
iterator for the elements in this set
public String toString(); //Returns a string
representation of this set
}
In: Computer Science
Explain how to search for a record (using hashing) in a file where the records originally were stored using modules method . for example the id was modulated by the size of the file.
In: Computer Science
Rewrite the following program so
that the counting of the a's and
total count are done be
separate functions
The code you turn in should have 2 functions
*/
#include<stdio.h>
int main(void){
char input[81];
// Input string
int a=0, total=0;
// counter variables
// Ask for an input string
puts(" Input a string of up to 80 characters
and\n"
" I will tell you how many a\'s it contains \n"
" as well as a total character count.\n\n");
fputs(" ",stdout);
// just make things line
up
// read the input string
fgets(input,80,stdin);
while(input[total] != '\0'){ // go through the string
if(input[total] == 'a' ||
input[total] == 'A') // count the number of a's
a++;
total++;
// total character
count
}
total--;
// fgets reads the newline -
we don't want to count that
// output the results
printf(" %d a\'s and %d total
characters.\n",a,total);
return 0;
}
In: Computer Science
MOAC70-410R2-Lab13 - Installing Domain Controllers
In: Computer Science
Implement a priority queue using a DoublyLinkedList
where the node with the highest priority (key) is the right-most
node.
The remove (de-queue) operation returns the node with
the highest priority (key).
If displayForward() displays List (first-->last) : 10 30 40
55
remove() would return the node with key 55.
You will then attach priorityInsert(long key) and priorityRemove() methods). AND Use the provided PQDoublyLinkedTest.java to test your code.
BOTH CODES SHOULD WORK TOGETHER, YOU JUST HAVE TO ADD priorityInsert(int). PLEASE PROVIDE CORRECT CODE.
class Link {
public long dData;
public Link next;
public Link previous;
public Link(long d) {
dData = d;
}
public void displayLink() {
System.out.print(dData + " ");
}
}
class DoublyLinkedList {
private Link first;
private Link last;
public DoublyLinkedList() {
first = null;
last = null;
}
public boolean isEmpty() {
return first == null;
}
public void insertFirst(long dd) {
Link newLink = new Link(dd);
if (isEmpty())
last = newLink;
else
first.previous = newLink;
newLink.next = first;
first = newLink;
}
public void insertLast(long dd) {
Link newLink = new Link(dd);
if (isEmpty())
first = newLink;
else {
last.next = newLink;
newLink.previous = last;
}
last = newLink;
}
public Link deleteFirst() {
Link temp = first;
if (first.next == null)
last = null;
else
first.next.previous = null;
first = first.next;
return temp;
}
public Link deleteLast() {
Link temp = last;
if (first.next == null)
first = null;
else
last.previous.next = null;
last = last.previous;
return temp;
}
public boolean insertAfter(long key, long dd) {
Link current = first;
while (current.dData != key){
current = current.next;
if (current == null)
return false;
}
Link newLink = new Link(dd);
if (current == last) {
newLink.next = null;
last = newLink;
}
else {
newLink.next = current.next;
current.next.previous = newLink;
}
newLink.previous = current;
current.next = newLink;
return true;
}
public Link deleteKey(long key) {
Link current = first;
while (current.dData != key) {
current = current.next;
if (current == null)
return null;
}
if (current == first)
first = current.next;
else
current.previous.next = current.next;
if (current == last)
last = current.previous;
else
current.next.previous = current.previous;
return current;
}
public void displayForward() {
System.out.print("List (first-->last): ");
Link current = first;
while (current != null)
{
current.displayLink();
current = current.next;
}
System.out.println("");
}
public void displayBackward() {
System.out.print("List (last-->first): ");
Link current = last;
while (current != null)
{
current.displayLink();
current = current.previous;
}
System.out.println("");
}
public void insertSorted(long key) {
if (isEmpty() || key < first.dData) {
insertFirst(key);
return;
}
Link current = first;
while (current.next != null) {
if (key >= current.dData && key <=
current.next.dData) {
Link lnk = new Link(key);
lnk.next = current.next;
current.next.previous = lnk;
current.next = lnk;
lnk.previous = current;
return;
}
current = current.next;
}
insertLast(key);
}
}
public class PriorityLinkQueue {
private DoublyLinkedList list;
public PriorityLinkQueue() {
list = new DoublyLinkedList();
}
public void insert(long key) {
list.insertSorted(key);
}
public long remove() {
if (list.isEmpty()) {
throw new RuntimeException("Priority Queue is empty!");
}
return list.deleteLast().dData;
}
public boolean isEmpty() {
return list.isEmpty();
}
public void displayForward() {
list.displayForward();
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
class PQDoublyLinkedTest.JAVA ->>> ONLY FOR TESTING, DO NOT CHANGE ANYTHING IN PQDoublyLinkedTest.JAVA
public class PQDoublyLinkedTest
{
public static void main(String[] args)
{ // make a new list
DoublyLinkedList theList = new DoublyLinkedList();
theList.priorityInsert(22); // insert at front
theList.priorityInsert(44);
theList.priorityInsert(66);
theList.priorityInsert(11); // insert at rear
theList.priorityInsert(33);
theList.priorityInsert(55);
theList.priorityInsert(10);
theList.priorityInsert(70);
theList.priorityInsert(30);
theList.displayForward(); // display list forward
Link2 removed = theList.priorityRemove();
System.out.print("priorityRemove() returned node with key:
");
removed.displayLink2();
} // end main()
} // end class PQDoublyLinkedTest
In: Computer Science