answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
solong [7]
2 years ago
3

Read integers from input and store each integer into a vector until 0 is read. Do not store 0 into the vector. Then, output the

values in the vector that are not equal to the last value in the vector, each on a new line.
Ex: If the input is -90 -10 22 -10 0, the output is:

-90
22
#include
#include
using namespace std;

int main() {

/* Your code goes here */

return 0;
}
Computers and Technology
1 answer:
Alexeev081 [22]2 years ago
3 0

Answer:

The program is as follows:

#include<iostream>

#include<vector>

using namespace std;

int main() {

vector<int> myInputs;

int num;

cin>>num;

while(num !=0){

   myInputs.push_back(num);

   cin>>num;}

for (int i = 0; i < myInputs.size(); i++){

       if(myInputs[myInputs.size()-1]!=myInputs[i]){

           cout << myInputs[i] << " ";        }

       }

return 0;

}

Explanation:

Declare integer vector of elements

vector<int> myInputs;

Declare num for integer inputs

int num;

Get input for num

cin>>num;

This loop is repeated until input is 0

while(num !=0){

Push the input to the vector

   myInputs.push_back(num);

Get another input

   cin>>num;}

Iterate through the vector elements

for (int i = 0; i < myInputs.size(); i++){

For vector elements not equal to the last element

       if(myInputs[myInputs.size()-1]!=myInputs[i]){

The element is printed

           cout << myInputs[i] << " ";        }

       }

You might be interested in
Give a recursive (or non-recursive) algorithm to compute the product of two positive integers, m and n, using only addition and
LiRa [457]

Answer:

Multiply(m,n)

1. Initialize product=0.

2. for i=1 to n

3.      product = product +m.

4. Output product.

Explanation:

Here we take the variable "product" to store the result m×n. And in this algorithm we find m×n by adding m, n times.

6 0
2 years ago
(NumberFormatException)Write the bin2Dec(String binaryString) method to convert a binary string into a decimal number. Implement
tresset_1 [31]

The following program will be used that prompts the user to enter a binary number as a string and displays decimal equivalent of the string.

<u>Explanation:</u>

NumberFormat.java

import java.util.Scanner;

public class NumberFormat{

public static void main(String[] args) {

      Scanner scan = new Scanner(System.in);

      try{

      System.out.println("Enter a binary string:");

      String s = scan.next();

      int integerValue = bin2Dec(Integer.parseInt(s));

      System.out.println("The decimal value of "+s+" is "+integerValue);

      }

      catch(NumberFormatException e){

          System.out.println(e);

      }

  }  

  public static int bin2Dec(int binaryNumber) throws NumberFormatException{

  int decimal = 0;

  int p = 0;

  try{

  while(true){

  if(binaryNumber == 0){

  break;

  } else {

  int temp = binaryNumber%10;

  decimal += temp*Math.pow(2, p);

  binaryNumber = binaryNumber/10;

  p++;

  }

  }

  }

  catch(NumberFormatException e){

      throw new NumberFormatException("Invalid binary number");

  }

  return decimal;

  }

}

Output:

Enter a binary string:

1011000101

The decimal value of 1011000101 is 709

5 0
2 years ago
2) Complete the get_num_of_characters() function, which returns the number of characters in the user's string. We encourage you
Lilit [14]

Explanation:

Number of characters: 46

String with no whitespace: Theonlythingwehavetofearisfearitself.

########################################################

def get_num_of_characters(inputStr):

   count = 0

   for i in range(0,len(inputStr)):

       count = count + 1

   #count = len(inputStr)

   return count

def output_without_whitespace(inputStr):

   #statement = statement.strip()

   statement2 = ' '

   for i in range(0,len(inputStr)):

        if(inputStr[i] == ' '):

           statement2 = statement2

       else:

           statement2 = statement2 + inputStr[i]

       

   inputStr = inputStr.replace(" ", "")

   return statement2

inputStr = input('Enter a sentence or phrase: ')

print()

print('You entered:', inputStr)

num = get_num_of_characters(inputStr)

print()

print('Number of characters:', num)

print('String with no whitespace:',output_without_whitespace(inputStr))

#if __name__ == '__main__':

   # Think I'm supposed to use this if statement

########################################################

'''ERROR MESSAGE WHEN RUNNING TEST

Unit test

0/1

Tests that get_num_of_characters() returns 46 for "The only thing we have to fear is fear itself."

Your output

Enter a sentence or phrase: Traceback (most recent call last):

 File "zyLabsUnitTestRunner.py", line 4, in <module>

   from zyLabsUnitTest import test_passed

 File "/home/runner/local/unit_test_student_code/zyLabsUnitTest.py", line 1, in <module>

   from main import get_num_of_characters

 File "/home/runner/local/unit_test_student_code/main.py", line 19, in <module>

   inputStr = input('Enter a sentence or phrase: ')

EOFError: EOF when reading a line'''

6 0
2 years ago
A vehicle fails an HC emission test at idle and 2,500 rpm, and the engine has an acceleration stumble. The heated oxygen sensor
Natalija [7]

I would say a defective O2 sensor

6 0
2 years ago
What best describes the purpose of the Recycle Bin (Microsoft Windows) and Trash (Apple Mac) features
alexandr1967 [171]
Its to delete the files from the computer that you no longer want. Once its put in the recycling bin it stays there, then when you empty it, its off your computer and there is no way you can get those files back. This can also free-up some space from your computer since mega and giga bites are being removed from your computer.
7 0
2 years ago
Read 2 more answers
Other questions:
  • In the game Singularity, broken objects can be restored to their original condition by reversing time. This is an example of whi
    12·2 answers
  • In a graphical user interface, which is a small symbol on the screen whose location and shape changes as a user moves a pointing
    10·1 answer
  • Write a program that first reads in the name of an input file, followed by two strings representing the lower and upper bounds o
    8·1 answer
  • The ______ network became functional in 1969, linking scientific and academic researchers across the United States. Group of ans
    7·2 answers
  • Create the strAnalysis() function that takes 1 string argument and returns a string message. The message will be an analysis of
    15·1 answer
  • Select which type of computer you would like to begin building, based on the needs of your new job: Frequent travel Maintaining
    7·1 answer
  • Drag each tile to the correct box.
    12·1 answer
  • Modify the TimeSpan class from Chapter 8 to include a compareTo method that compares time spans by their length. A time span tha
    10·1 answer
  • Array A is not a heap. Clearly explain why does above tree not a heap? b) Using build heap procedure discussed in the class, con
    15·1 answer
  • Please can someone help me answer this question.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!