Write a simple arithmetic expression translator that reads in expressions such as 25.5 + 34.2 and displays their value. Each expression has two numbers separated by an arithmetic operator. (Hint: Use a switch statement with the operator symbol (type char) as a selector to determine which arithmetic operation to perform on the two numbers. For a sentinel, enter an expression with zero for both operands.)

Answers

Answer 1
Answer:

Answer:

Following are the program in the C++ Programming Language.

//header file

#include<iostream>

//header file

#include <bits/stdc++.h>

//namespace

using namespace std;

//set main function

int main()

{

//set float type variables

float a,s,m,d,c,b,g;

//print message and get variable from the user

cout<<" Enter The First Number : ";

cin>>c;

//print message and get variable from the user

cout<<" Enter The Second Number: ";

cin>>b;

again:

//get variable from the user for Operation

cout<<" Enter the Operation which you want : ";

char choice;

cin>>choice;

//Addition

a=c+b;

//Subtraction

s=c-b;

//Multiplication

m=c*b;

//Division

d=c/b;

//Modulus

g=fmod(c, b);

//set switch statement

//here is the solution

 switch(choice)

 {

   case '+':  

     cout<<"Addition: "<<a<<endl;

     goto again;

     break;

   case '-':

     cout<<"Subtraction: "<<s<<endl;

     goto again;

     break;

   case '*':

     cout<<"Multiplication: "<<m<<endl;

     goto again;

     break;

   case '/':

     cout<<"Division: "<<d<<endl;

     goto again;

     break;

   case '%':

     cout<<"Modulus: "<<g<<endl;

     goto again;

     break;

   default:

     cout<<"Exit";

     break;

 }

return 0;

}Explanation:

Here, we define the required header files then, we set main function.

  • set float type variables a,s,m,d,c,b,g.
  • Get input from the user for operation in the variable c,d.
  • Set character type variables in which we get input from the user for operations.
  • Then, we perform some operations.
  • Set switch statement which display the output according to the user an if user input wrong then statement breaks.

Related Questions

1. What is the difference between computer organization and computer architecture? 2. What is an ISA? 3. What is the importance of the Principle of Equivalence of Hardware and Software? 4. Name the three basic components of every computer. 5. To what power of 10 does the prefix giga- refer? What is the (approximate) equivalent power of 2? 6. To what power of 10 does the prefix micro- refer? What is the (approximate) equivalent power of 2?
Write a java program that use multiple arrays This is a simple array program which does not use an "external class & demo program" If you wish, you may break it down into methods, but that is not required. a. Set up 4 arrays which hold data about 6 items you want to sell: [make them up] int[ ] itemnum int[ ] quantity double[ ] price double[ ] sales b. Set up loops to load the itemnum, quantity and price arrays c. Set up another loop to calculate values for the sales array. [= price * quantity] d. Set up another loop to print the item number and sales amount for each transaction . e. Set up another loop to calculate the total sales of all 6 items f. print the total sales amount
Consider the following two code segments, which are both intended to determine the longest of the three strings "pea", "pear", and "pearl" that occur in String str. For example, if str has the value "the pear in the bowl", the code segments should both print "pear" and if str has the value "the pea and the pearl", the code segments should both print "pearl". Assume that str contains at least one instance of "pea".I.if (str.indexOf("pea") >= 0){System.out.println("pea");}else if (str.indexOf("pear") >= 0){System.out.println("pear");}else if (str.indexOf("pearl") >= 0){System.out.println("pearl");}II.if (str.indexOf("pearl") >= 0){System.out.println("pearl");}else if (str.indexOf("pear") >= 0){System.out.println("pear");}else if (str.indexOf("pea") >= 0){System.out.println("pea");}Which of the following best describes the output produced by code segment I and code segment II?Both code segment I and code segment II produce correct output for all values of str.Neither code segment I nor code segment II produce correct output for all values of str.Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pear" but not "pearl".Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pearl".Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pea" but not "pear".
Language: JavaYour task is to complete the logic to manage a twenty-four-hour clock (no dates, just time) that tracksthe hours, minutes, and sections, and various operations to adjust the time. The framework for yourclock is in the Time class with the four methods you must complete.1.) advanceOneSecondâ A user calls this method to advance the clock by one second.a. When the seconds value reaches 60, it rolls over to zero.b. When the seconds roll over to zero, the minutes advance.So 00:00:59 rolls over to 00:01:00.c. When the minutes reach 60, they roll over and the hours advance.So 00:59:59 rolls over to 01:00:00.d. When the hours reach 24, they roll over to zero.So 23:59:59 rolls over to 00:00:00.2.) compareTo â The user wants to know if a second time is greater than or less than the timeobject called, assuming both are on the same date.a. Returns -1 if this Time is before otherTime.b. Returns 0 if this Time is the same as otherTime.c. Returns 1 if this Time is after otherTime.3.) add â Adds the hours, minutes, and seconds of another time (the offset) to the current timeobject. The time should ârolloverâ if it exceeds the end of a 24 hour period.4.) subtract â Subtracts the hours, minutes, and seconds of another time (the offset) fromthe current time object. The time should âroll backâ if it precedes the beginning of a 24 hourperiod.________________________________________________________________________package clock;/*** Objects of the Time class hold a time value for a* European-style 24 hour clock.* The value consists of hours, minutes and seconds.* The range of the value is 00:00:00 (midnight) to 23:59:59 (one* second before midnight).*/public class Time {private int hours;private int minutes;private int seconds;/*** Add one second to the current time.* When the seconds value reaches 60, it rolls over to zero.* When the seconds roll over to zero, the minutes advance.* So 00:00:59 rolls over to 00:01:00.* When the minutes reach 60, they roll over and the hours advance.* So 00:59:59 rolls over to 01:00:00.* When the hours reach 24, they roll over to zero.* So 23:59:59 rolls over to 00:00:00.*/public void advanceOneSecond(){}/*** Compare this time to otherTime.* Assumes that both times are in the same day.* Returns -1 if this Time is before otherTime.* Returns 0 if this Time is the same as otherTime.* Returns 1 if this Time is after otherTime.*/public int compareTo(Time otherTime){return 0;}/*** Add an offset to this Time.* Rolls over the hours, minutes and seconds fields when needed.*/public void add(Time offset){}/*** Subtract an offset from this Time.* Rolls over (under?) the hours, minutes and seconds fields when needed.*/public void subtract(Time offset){}
A computer processor stores numbers using a base of: _____.a) 2b) 10c) 8d) 16

You text file begins with the following rows. The pattern is a description of the item to be repaired, its color, and the issue. bike, red, flat tire bike, blue, broken chain skate, blue, loose wheel mitt, red, torn lace Your program starts with the following lines. import csv aFile = open("data\broken.txt","r") aReader = csv.reader(aFile) countRed = 0 for item in aReader: When you write code to count the number of times red is the color, what is the index of "red"?

Answers

Answer: the answer is 1

Explanation:

edge 2021

Should I get hollow knight, hyper light drifter, Celeste, or stardew valley for switch

Answers

Ooh, very tough question. I've played both Celeste, and Hollow knight. So I cant say anything for the other two games.

Celeste and Hollow Knight are both platforming games, so that was something I was interested in. And both also have deep morals to learn and stories to enjoy. Celeste basically follows Madeline, who's had some emotional problems in the past as she's trying to climb a mountain. In this mountain, a part of her escapes and becomes a but of a antag.

I loved the background, and the characters in this game. But there were a lot of parts in the game that frustrated me and I got very close to just all-out giving up on the game. I still loved it though.

But don't even get me started on Hollow Knight. LIKE OH My GOD, I am obsessed with Hollow Knight and its beauty! I have almost every piece of merchandise, every plush, every t-shirt, charm, sticker, pins, and all the DLC packs. This game is an absolute masterpiece. I cant say anything without giving off the background and lore behind the game. and I'll be honest, there's been a couple of times where I was so touched with the game, that I just started crying. There's lovable characters like Hornet, our little Ghost, Myla (oml rip Myla you beautiful baby), and of course laughable Zote. Its so beautiful. The art is stunning, the animation is so clean. And if you do end up getting Hollow Knight, then your going to be even more excited because Team Cherry is actually in the works of creating the sequel (or prequel) of Hollow Knight, which is Hollow Knight ; Silksong! Definitely go and watch the Nintendo trailer for that game! I've been so excited about it for months and Ive been watching the trailer almost every day.

Anyway, sorry this is so long. But i'm going to go with my gut and say Hollow Knight. Its beautiful, amazing, and overall just..perfect.

Answer:

hollow knight is pretty good

Explanation:

Choose the best collection for each situation.You need to keep a record of the ages of the last 50 customers visit a restaurant. As new customers come in you delete the age that has been in the list the longest.

You need to store the GPS coordinates of the hospitals in a state in order to find the nearest hospital for ambulance helicopters.

You write a loop to save anywhere from 10 to 100 values from a user. You will pass the collection to a function to find the average.

Answers

Answer:

Deque: You need to keep a record of the ages of the last 50 customers visit a restaurant. As new customers come in you delete the age that has been in the list the longest.

Tuple: You need to store the GPS coordinates of the hospitals in a state in order to find the nearest hospital for ambulance helicopters.

List: You write a loop to save anywhere from 10 to 100 values from a user. You will pass the collection to a function to find the average.

Explanation: Just got the results back no thanks to the guy above

Write a JAVA program to sort a given array of integers (1 Dimensional) in ascending order (from smallest to largest). You can either get the array as input or hardcode it inside your program.

Answers

Answer:

import java.util.Arrays;

public class sort{

    public static void main(String []args){

       int[] arr = {2,6,9,1,5,3};

       int n = arr.length;

       Arrays.sort(arr);

       for(int i=0;i<n;i++){

          System.out.println(arr[i]);

       }    

    }

}

Explanation:

first import the library Arrays for using inbuilt functions.

create the main function and define the array with elements.

then, use the inbuilt sort function in java which sort the array in ascending order.

syntax:

Arrays.sort(array_name);

then, use for loop for printing the each sorting element on the screen.

IN PYTHON Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, and output all integers less than or equal to that value.

Ex: If the input is:

Enter the number of integers in your list: 5
Enter the 5 integers:
50
60
140
200
75
Enter the threshold value: 100
the output is:

The integers that are less than or equal to 100 are:
50
60
75

The 5 indicates that there are five integers in the list, namely 50, 60, 140, 200, and 75. The 100 indicates that the program should output all integers less than or equal to 100, so the program outputs 50, 60, and 75. Such functionality is common on sites like Amazon, where a user can filter results. Your code must define and call the following two functions: def get_user_values() def output_ints_less_than_or_equal_to_threshold(user_values, upper_threshold) Utilizing functions will help to make your main very clean and intuitive.

Answers

Answer:

def output_ints_less_than_or_equal_to_threshold(user_values, upper_threshold):

 for value in user_values:

     if value < upper_threshold:

         print(value)  

def get_user_values():

 n = int(input())

 lst = []

 for i in range(n):

     lst.append(int(input()))

 return lst  

if __name__ == '__main__':

 userValues = get_user_values()

 upperThreshold = int(input())

 output_ints_less_than_or_equal_to_threshold(userValues, upperThreshold)

Explanation:

Suppose an array with six rows and eight columns is stored in row major order starting at address 20 (base 10). If each entry in the array requires only one memory cell, what is the address of the entry in the third row and fourth column?

Answers

Answer:

39

Explanation:

Since each of the address occupies only 1 memory cell and the 2-D array is row-major 2-D array.So the elements will be filled row wise.First the first row will be fully filled after that second row and so on.Since we want the address of the element at third row and fourth column.

we can generalize this :

address of the element at ith row and jth column=s + ( c * ( i - 1 ) + ( j - 1 ) ).

s=Starting address.

c=Number of columns in the 2-D array.

address=20+(8*(3-1)+(4-1))

=20+(8*2+3)

=20+16+3

=39

Or you can make a matrix of six rows and eight columns and put first cell with 20.Start filling the elements row wise one by one and look what is the count of 3rd row and 4th column.