Write a C or C++ program a pseudo C program (based on chapter 2 in the book) and then use these programs to develop a MIPS program that gets an integer input from the user, and based on the input returns the minimal or maximal value stored in a static initialized array. The following are detailed instructions:
1) The program generates a static initialized array with 10 integers (using the .word directive). 2) The program prompts the user to enter 1 if she/he wants to find the minimal value stored in the array, and 2 if she/he wants the maximal value stored. 3) If the user enters 1, then the program finds the minimal value stored in the array and prints out this value. 4) If the user enters 2, then the program finds the maximal value stored in the array and prints out this value. 5) If the user enters any other value, then the program prompts him/her again to enter a valid number. 6) After displaying the min (or max), the program terminates.
///////////////////////////////////////////////////////////////////// C++ CODE :///////////////////////////////////////////////////////////////////////
#include <iostream>
using namespace std;
int main(){
int maximal,minimal,choice;
static int array[10]={1,2,5,7,9,12,45,67,88,23};
maximal=array[0];
for(int i=0;i<10;i++){
if (maximal < array[i])
maximal = array[i];
}
minimal = array[0];
for (int j=0;j<10;j++)
{
if (minimal>array[j])
minimal=array[j];
}
cout<<"Enter 1 if she/he wants to find the minimal value stored in the array "<<endl;
cout<<"Enter 2 if she/he wants the maximal value stored in the array "<<endl;
cin>>choice;
if(choice==1){
cout<<"Minimal Value is:"<<minimal<<endl;
}else if (choice==2){
cout<<"Maximal Value is:"<<maximal<<endl;
}else if(choice!=1&&choice!=2){
cout<<"Enter a valid number."<<endl;
cin>>choice;
if(choice==1){
cout<<"Minimal Value is:"<<minimal<<endl;
}else if(choice==2){
cout<<"Maximal Value is:"<<maximal<<endl;
}
}
return 0;
}
///////////////////////////////////////////////////////////////////// MIPS CODE:////////////////////////////////////////////////////////////////////////
DATA SEGMENT
ARR DB 5,3,7,1,9,2,6,8,4
LEN DW $-ARR
MIN DB ?
MAX DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,ARR
MOV AL,ARR[SI]
MOV MIN,AL
MOV MAX,AL
MOV CX,LEN
REPEAT:
MOV AL,ARR[SI]
CMP MIN,AL
JL CHECKMAX
MOV MIN,AL
CHECKMAX:
CMP MAX,AL
JG DONE
MOV MAX,AL
DONE:
INC SI
LOOP REPEAT
MOV AH,4CH
INT 21H
CODE ENDS
END START
///////////////////////////////////////////////////////////////////// PSEUDO CODE:////////////////////////////////////////////////////////////////////////
maiximal=0
minimal=0
maximal=array[0]
for i=0 to 10
if array[i]>maiximal
maximal =array[i]
End-if
End-for
print "Maximal " maximal
minimal=array[0]
for i=0 to 10
if array[i]<minimal
maximal =array[i]
End-if
End-for
print "Minimal: " minimal
Write a C or C++ program a pseudo C program (based on chapter 2 in the...
Write a Java program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one of the following: +, -, *, /, or % representing the usual arithmetic operators (Each operation should be done on numbers negative(-) to positive(+), positive(+) to negative(-), negative(-) to negative(-), and positive(+)...
1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in); } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...
write a c++ program that prompts a user for a number then attempts to allocate an array of as many integers as the user enters. In other words, the program might prompt the user with a line like: “How many integers would you like to allocate?” It should then allocate as many integers as the user enters. The program should then wait for the user to press enter before deleting the allocated array and quitting. We will use this time...
C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional arrays. Your program should include three functions: one for getting input data, one for calculating the sum of matrices, and one for printing the result. a) Function inputMatrix: This Function prompts the user to enter the data and stores data inside two-dimensional array. b) Function addMatrices: This function calculatesthe sum result of two matrices. c) Function printMatrix: This function prints the matrix to screen....
Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...
Problem 1: Dynamic Grocery Array Using Java to write a program that prompts the user to enter an item’s name for each position in the array. The program then prints uses a loop to output the array. Example 1: Banana 2: Orange 3: Milk 4: Carrot 5: Chips Banana, Orange, Milk, Carrot, Chips Problem 2: Print Characters in String Array Declare a string array of size 5. Prompt the user enters five strings that are stored in the array....
Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...
Question 39 Language C++ Question 39 15 pts Implement a program that finds the shortest string in a dynamically allocated array of strings. The program first asks the user for the number of names needed. Afterwards, the user is prompted to enter each name. The program then passes the array to a function. The function returns the index of the shortest element. The program then prints out the shortest element and the index where it is stored in the array....
Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...
Write a program which: - prompts the user for 2 numerical inputs - stores their two inputs in variables as floats - Use a while in loop to ask a user for a valid operation: (if the user's input operation isn't one of those listed above, instead print a message telling them so, and continue asking for the valid operation) - prompts the user for an arithmetic operation ( + - * / %) - stores the user's input as...