Takes a string and removes all spaces and special characters,
and converts
// to upper case, returning the result
// Pre: inString contains a string
// Post: Returns a string with all spaces and special characters
removed and
// converted to upper case
in c++ please
In: Computer Science
implement heap sort algorithm continuing off this
#include <iostream>
#define MAX_INT 2147483647
using namespace std;
int main(int argc,char **argv) {
int* array;
int arraySize = 1;
// Get the size of the sequence
cin >> arraySize;
array = new int[arraySize];
// Read the sequence
for(int i=0; i<arraySize; i++){
cin >> array[i];
}
In: Computer Science
Our MIPS assembly version will “compile” the following C program: #include void Compare(int b1, int h1, int b2, int h2); int Area(int b, int h); int main(int argc, char **argv) { int base1, base2, height1, height2; base1=10; base2=12; height1=8; height2=7; Compare(base1, height1, base2, height2); return 0; } void Compare(int b1, int h1, int b2, int h2) { int A1=Area(b1, h1); int A2=Area(b2, h2); if (A1>=A2) printf("Area1 is greater than Area2.\n"); else printf("Area2 is greater than Area1.\n"); } int Area(int b, int h) { int A=(b*h)/2; return A; } The MIPS Assembly Triangles Program .data: b1: .word 10 h1: .word 12 b2: .word 8 h2: .word 7 msg1: .asciiz "Area1 greater than Area2.\n" msg2: .asciiz "Area2 greater than Area1.\n" 5 Adriana WISE—CS301 Thursday, September 26, 2019 debug1: .asciiz "Area1=" debug2: .asciiz "Area2=" newline: .asciiz "\n" .text: main: lw $a0, b1 lw $a1, h1 lw $a2, b2 lw $a3, h2 jal Compare li $v0, 10 syscall Compare: subi $sp, $sp, 4 sw $ra, 0($sp) jal Area add $s0, $v0, $zero la $a0, debug1 li $v0, 4 syscall add $a0, $s0, $zero li $v0, 1 syscall la $a0, newline li $v0, 4 syscall la $a0, debug2 li $v0, 4 syscall add $a0, $a2, $zero add $a1, $a3, $zero jal Area add $a0, $v0, $zero li $v0, 1 syscall la $a0, newline li $v0, 4 syscall sub $s0, $s0, $v0 6 Adriana WISE—CS301 Thursday, September 26, 2019 bltz $s0, LESS j MORE LESS: li $v0, 4 la $a0, msg2 syscall MORE: li $v0, 4 la $a0, msg1 syscall lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra Area: subi $sp, $sp, 8 sw $ra, 0($sp) sw $s0, 4($sp) mul $s1, $a0, $a1 srl $v0, $s1, 1 lw $ra, 0($sp) lw $s0, 4($sp) addi $sp, $sp, 8 jr $ra Output: Area1=40 Area2=42 Area1 greater than Area2. -- program is finished running — Re-write the Triangles C and MIPS programs to read the triangles’ bases and heights as interactive user input. Write a MIPS assembly program (instructions at the end of Lecture 5 notes) to compare the areas of two triangles, taking as user input the bases and heights of the two triangles, and using two functions, Compare() and Area(), where Compare() calls Area(). For practice, also modify the existing C program to accept user input, as presented in class (lecture notes assume hard-coded values).
In: Computer Science
I am stuck on the following problem please and it has to be in python!
1) Initially, create a list of the following elements and assign the list to a variable "thing".
"Mercy", "NYU", "SUNY", "CUNY"
2) print the list above
3) add your last name to the list
4) print the list
5) add the following elements as a nested list to the list:
"iPhone", "Android"
6) print the list
7) add the following list to the end of the list as elements:
["MIT", "CMU"]
8) print the list
9) add the following nested list to the third position of the list thing:
[30, 40+1]
10) print the list
11) delete "SUNY" from the list. # revised this question on 9/24 8:41pm!
12) print the list
13) add "Mercy" to the second last in the list (so "Mercy" should be in between "MIT" and "CMU"):
14) print the list
15) count "Mercy" in the list and print.
16) print the number of the top-level elements in the list.
17) In Step 10 above, explain why 40+1 is entered 41 to the list.
Challenge) Can we remove an element from a nested list? If yes, explain how in plain text. If not, explain why not
Challenge) Can we count each every element in a list, which may contain nested lists? If yes, explain how in plain text. If not, explain why not
In: Computer Science
Problem 2:
(20 pts) Create a Patient class which has private fields for patientid, lastname,
firstname, age, and email. Create public data items for each of these private fields with get and
set methods. The entire lastname must be stored in uppercase. Create a main class which
instantiates a patient object and sets values for each data item within the class. Display the
data in the object to the console window
In: Computer Science
What happens if the stack and heap segments collide (i.e., one overwrites part of the other)? Why is this dangerous? How would you prevent it?
In: Computer Science
In: Computer Science
how would I be able to implement a hash table into a spell checker program while using a StringNode class in java that checks for spelling mistakes?
In: Computer Science
import java.util.Scanner;
public class test {
public static void main(String args[]){
char letter;
int number = 0;
Scanner in = new
Scanner(System.in);
System.out.print("Enter a letter:
");
letter = in.next().charAt(0);
if(letter == 'A' || letter == 'B'
|| letter == 'C') number = 2;
if(letter == 'D' || letter == 'E'
|| letter == 'F') number = 3;
if(letter == 'G' || letter == 'H'
|| letter == 'I') number = 4;
if(letter == 'J' || letter == 'K'
|| letter == 'L') number = 5;
if(letter == 'M' || letter == 'N'
|| letter == 'O') number = 6;
if(letter == 'P' || letter == 'R'
|| letter == 'S') number = 7;
if(letter == 'T' || letter == 'U'
|| letter == 'V') number = 8;
if(letter == 'W' || letter == 'X'
|| letter == 'Y') number = 9;
if(letter == 'Q' || letter == 'Z')
number = -1;
if(number > 0)
System.out.println("Letter " + letter + " corresponds to digit " +
number);
else System.out.println("Letter " +
letter + " is not used in a telephone");
}
}
My question is how can I use Switch statement in this program?
In: Computer Science
Write a function named "replacement" that takes a string as a parameter and returns an identical string except with every instance of the character "w" replaced with the character "v"
My code:
function replacement(word){
var str=word;
var n=str.replace("w","v");
return n;
}
Syntax Error: function replacement incorrect on input
Not sure how to fix? Can't use a loop for answer
In: Computer Science
In Modern Infrastructure strategy there are 2 basic models to consider. Keep in mind choosing the best for the business is the right strategic decision.
Model 1-Traditional onsite of co-located data center facility. This houses your network, storage and compute technologies. You purchase and manage the equipment and your entire network/compute environment yourself.
Model 2-Newer Cloud or SAS model. In this model all the network, comput, storage lives in the cloud or at a service provider's datacenter. It's model 1 but your paying someone to host and maintain the environment for you.
Compare and contrast the 2. What is the right strategy fr a smaller start up firm? What about a larger more established firm. Support your arguments and create a strength and weakness argument for each small vs larger firm. Remember concerns like cost, scale, security etc-as discussed in class.
In: Computer Science
My add method is not working to add elements into an arrayList in java.
This is the error message I keep getting:
Exception in thread "main" java.lang.NullPointerException
at assignment1.ArrayBag.add(ArrayBag.java:50)
at assignment1.Main.main(Main.java:21)
BUILD FAILED (total time: 0 seconds)
The following are all the methods I've created.
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment1;
/**
*
* @author Daniela Garcia Toranzo ; PID: 5674893
*/
public class ArrayBag implements Bag {
private int SIZE = 10;
private String[] bag;
private int length;
public void ArrayBag() {
bag = new String[10];
length = 0;
}
@Override
public boolean isEmpty() {
return length == 0;
}
@Override
public void print() {
for (int i = 0; i < bag.length; i++) {
if (bag[i] != null) {
System.out.print(bag[i] + " ");
}
}
}
@Override
public void add(String s) {
if (isFull() == true) {
System.out.println("Arraylist is full, cannot add anything else");;
} else {
bag[length] = s;
length++;
}
}
@Override
public void remove(String s) {
boolean found = false;
String x, y = "";
for (int i = 0; i < length; i++) {
x = bag[i].toString();
if (x.equals(y)) {
found = true;
bag[i] = bag[length - 1];
bag[length - 1] = null;
length--;
}
}
}
@Override
public int count(String s) {
int counter = 0;
for (int i = 0; i < length; i++) {
if (s.equals(bag[i])) {
counter++;
}
}
return counter;
}
private boolean isFull() {
if (length > SIZE) {
System.out.println("ArrayList is Full");
}
return length > SIZE;
}
}
In: Computer Science
(Using Matlab) Write a function to "smooth" a black-and-white image by replacing each pixel by the average of itself and its neighbors. In MATLAB a black-and-white image is just a matrix of 1s and 0s - 1 represents white, and 0 represents black.
To keep the algorithm simple, ignore the edges of the image - that is, do not change the first and last rows and columns.
function name = smooth_image()
input argument = input matrix
output argument = output matrix
The algorithm can be described as follows:
In: Computer Science
```please convert this code to make only using for loop not while loop
#include
#include
#define MAX_SIZE 500
int main()
{
char str[MAX_SIZE];
char tosearch[MAX_SIZE];
char part1[100];
char part2[100];
int cursor = 0, i, cnt1 = 0, cnt2 = 0, cnt = 0;
int j = 0;
int a = 0;
int b = 0;
int total = 0;
printf("Enter any string: ");
gets(str);
printf("Enter word to search occurrences: ");
gets(tosearch);
for (i = 0; i < strlen(tosearch); i++)
{
if (tosearch[i] == '*')
{
for (j = 0; j < i; j++)
{
part1[j] = tosearch[j];
}
a = j;
}
}
for (j = 0; j < strlen(tosearch) - a; j++)
{
part2[j] = tosearch[a + j + 1];
}
for (j = 0; j < a; j++)
{
printf("%c", part1[j]);
}
printf("\n");
for (j = 0; j < strlen(tosearch) - a - 1; j++)
{
printf("%c", part2[j]);
}
printf("\n");
b = strlen(part2);
while (cursor < strlen(str)) { // while the cursor is smaller
than length of main string while loop goes on
while (cnt1 != a) { // if the cnt1 is smaller than the part1
length the while loop goes on
if (str[cursor] == part1[0]) { // if the str[cursor] is correspond
to the first word of part1 go to for loop
for (i = 0; i < a; i++) {
if (str[cursor + i] == part1[i])
{
cnt1++; // count the number of matching letter of part1 and main
string
}
else { // else the cnt1 goes to 0 again and cursor goes
forward
cnt1 = 0;
cursor++;
break;
}
}
}
if (cursor > strlen(str) || cnt1 == a)
{
break;
}
cursor++; // cursor goes to the next letter
}
cursor += a; printf("the value of cursor %d ", cursor);
while (cnt2 != b) { // if cnt2 is less than the length of part2 the while loop goes on
if (str[cursor] == part2[0]) { // if the str[cursor] correspond
with part2[0] for loop goes on
for (i = 0; i < b; i++) {
if (str[cursor + i] == part2[i])
{
cnt2++; // count the matching letter of str and part2
}
else {
cnt2 = 0; // else cnt2 goes to 0 and cursor move on break free from
the for loop
cursor++;
break;
}
}
}
if (cursor > strlen(str) || cnt2 == b) // if the cursor is
larger than the strlen or cnt2 == (the length of part2) break
free
break;
cursor++; // move on to the next letter of the main string
}
if (cursor + b > strlen(str))
break;
cnt++;
cnt1 = 0;
cnt2 = 0;
}
printf("tot %d\n", cnt);
}
In: Computer Science
Define a class Fraction3YourName as follows,
/**
* Program Name: Fraction3YourName.java
* Discussion: Fraction3Yourname class
* written By:
* Date: 2019/09/19
*/
public class Fraction3YourName {
private int sign;
private int num;
private int denom;
public Fraction3YourName() {
//sign = ;
//denom = ;
}
public Fraction3YourName(int n) {
//sign = ;
//num = n;
//denom = ;
}
public Fraction3YourName(int s, int n, int d) {
//sign = s;
//num = n;
//denom = d;
}
}
You are asked to
Complete the definitions for the given constructors; and
Provide additional method members to allow the performance of
four simple
arithmetic operations: (1) Addition, (2) Subtraction, (3)
Multiplication, and (4)
Division; and
Provide one method member print() to display the
Fraction3YourName object.
/** REQUIRED PROGRAM OUTPUT
****************************************
* MENU – HW #3 *
* (1) Creating 2 Fraction3 Objects *
* (2) Performing Arithmetic Operations *
* (3) Displaying Fraction3 Objects *
* (4) Quit *
****************************************
Enter your option (1 through 4): 5
You are funny!
****************************************
* MENU – HW #3 *
* (1) Creating 2 Fraction3 Objects *
* (2) Performing Arithmetic Operations *
* (3) Displaying Fraction3 Objects *
* (4) Quit *
****************************************
Enter your option (1 through 4): 2
Creating 2 Fraction3 Objects –
// Your details
****************************************
* MENU – HW #3 *
* (1) Creating 2 Fraction3 Objects *
* (2) Performing Arithmetic Operations *
* (3) Displaying Fraction3 Objects *
* (4) Quit *
****************************************
Enter your option (1 through 4): 3
Displaying Fraction3 Objects –
// Your details
****************************************
* MENU – HW #3 *
* (1) Creating 2 Fraction3 Objects *
* (2) Performing Arithmetic Operations *
* (3) Displaying Fraction3 Objects *
* (4) Quit *
****************************************
Enter your option (1 through 4): 4
Performing Arithmetic Operations –
// Your details
****************************************
* MENU – HW #3 *
* (1) Creating 2 Fraction3 Objects *
* (2) Performing Arithmetic Operations *
* (3) Displaying Fraction3 Objects *
* (4) Quit *
****************************************
Enter your option (1 through 4): 4
Having fun!
by java programming
In: Computer Science