1answer.
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
Romashka [77]
3 years ago
6

Create an empty text document name "input.txt" and copy the example contents from below: 5 105 15 20 35 47 The first value in th

e file tells you how many ints (the type must be int!) are in the file. The rest of the values are the ints you want to store. Create a program that reads in the first value, always an int, that tells you how many values are in the file. Then, create an array to store all of those values. After you've read in the values display them to the screen in the following format: Contents of input.txt: [105, 15, 20, 35, 47] Input a value to search for: The search prompt obtains a value from the user and confirms whether or not it is in the array. Example: Contents of input.txt: [105, 15, 20, 35, 47] Input a value to search for: 5 5 is not in the array. Do you wish to quit (y/n): n Input a value to search for: 105 105 is in the array. Do you wish to quit (y/n): y
Computers and Technology
1 answer:
agasfer [191]3 years ago
7 0

Answer:

  1. with open("input.txt") as file:
  2.    data = file.read()
  3.    inputList = data.split(" ")
  4.    count = int(inputList[0])
  5.    numArr = []
  6.    for i in range(1, count+1):
  7.        numArr.append(int(inputList[i]))
  8.    
  9.    print(numArr)
  10. search = int(input("Input a value to search for: "))
  11. if search in numArr:
  12.    print("Value found in array")
  13. else:
  14.    print(str(search)+ " is not in the array")
  15. choice = input("Do you wish to quit (y/n):")
  16. while(choice != "y"):
  17.    search = int(input("Input a value to search for: "))    
  18.    if search in numArr:
  19.        print("Value found in array")
  20.    else:
  21.        print(str(search)+ " is not in the array")
  22.    
  23.    choice = input("Do you wish to quit (y/n):")  

Explanation:

Firstly, we open a file stream to read the text file and use split method to break the input into a list of individual numbers (Line 1 - 3). We set the first item of the inputList to count variable and create a numArr list (Line 4-5).

Use a for loop to populate the number from inputList to numArr (Line 6-7) and display the number from the list (Line 9).

Next, prompt user to search for a number from list (Line 11).

If the input is matched with one of the item in numArr, display found message or display a not found message if the input is not available in the numArr (Line 13 -16). Prompt the user again to check if the user wish to quit the search (Line 18). If not, repeat the same process to input a search value and check the value is found in the numArr and display appropriate message (Line 21 - 28).

You might be interested in
Give two reasons why it is important to upgrade your browser when a new version becomes available.
kupik [55]
1. Higher speed
2. New features
3. Less bugs
4. Upgrades
4 0
3 years ago
A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Ab
Pavlova-9 [17]

Answer:

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

//header file

#include <iostream>

//header file for string

#include <string>

#include<cstring>

//using namespace

using namespace std;

//define Function to checks the string is passed is a Palindrome or not

bool is_Palin(string strng, int start_Position, int end_Position)

{

//set the if Conditional statement

if(start_Position >= end_Position)

{

return true;

}

//Check if the character is not the alphabet

if(!isalpha(strng[start_Position]))

{

//Update the starting position  

start_Position += 1;

//call Recursive function

return is_Palin(strng, start_Position++, end_Position);

}

//Check if the character is not the alphabet

if(!isalpha(strng[end_Position]))

{

//Update the end position

end_Position -= 1;

//call Recursive function

return is_Palin(strng, start_Position, end_Position--);

}

//Check if the characters are same or not same

if(tolower(strng[start_Position]) != tolower(strng[end_Position]))

{

return false;

}

//Update the positions

start_Position = start_Position + 1;

end_Position = end_Position - 1;

//call Recursive function

return is_Palin(strng, start_Position, end_Position);

}

//define Main function

int main()

{

string strng;

//get string from the user

cout << "\n\n Enter a string: ";

getline(cin, strng);

//Check for the palindrome

if(is_Palin(strng, 0, strlen(strng.c_str())-1))

{

 //then print message

cout << "\n Is a Palindrome!!!! \n";

}

//otherwise

else

{

//then print message

cout << "\n Is not a Palindrome!!!! \n";

}

return 0;

}

<u>Output:</u>

Enter a string:  Able was I, ere I saw Elba

Is a Palindrome!!!!

Explanation:

Here, we define a boolean data type function "is_Palin" to check the string which passed through is palindrome or not and pass and pass two integer type arguments for starting position and ending position and pass one string data type argument to pass string, inside the function.

  • Set the if conditional statement to check the condition if the start_position of the string is greater than end _position of the string then return true.
  • Set the if conditional statement to check the condition the start_position of the staring is alphabet then, update the start_position and call the recursion function.
  • Again set the if conditional statement to check the condition the end_position of the staring is alphabet then, update the end_position and call the recursion function.
  • Set the if conditional statement to check the condition if the start_position of the string is not equal to the end _position of the string then, return false.
  • Then, update the start_position and end _position of the string increment by 1 then, call the recursive function and then, close the function.

Finally, we define the main function and pass string through calling and passing and argument list in its parameter.  

5 0
3 years ago
For which input values will the following loop not correctly compute the maximum of the values? 1. Scanner in = new Scanner (Sys
My name is Ann [436]

Answer:

The answer is "Option d".

Explanation:

Please find the complete question in the attached file.

8 0
3 years ago
In 1971, Intel created and marketed the first microprocessor chip, called the Intel 4004. What was significant about this invent
PilotLPTM [1.2K]
The answer is D

<span>D) It allowed computers to be smaller because the chip allowed for the creation of computer components with varying capabilities.</span>
7 0
3 years ago
What is a symbol such as a heavy dot or another character that precedes a text in a power point
Fantom [35]

Answer:

<em>I </em><em>think </em><em>the </em><em>answer </em><em>is </em><em>a </em><em>bullet.</em>

<em>Hope </em><em>this </em><em>helps</em>

4 0
2 years ago
Other questions:
  • Which part of a window lets you see a fileâs contents without opening the file?
    9·1 answer
  • When you use the ip address of the web server, the correct site is displayed?
    15·1 answer
  • "what are the problems with tcp over wireless network?"
    15·1 answer
  • At the beginning of this month, the balance of Reed's checking account was $692.35. So far this month, he has received a paychec
    13·2 answers
  • How to engage more underrepresented and under resourced students in stem programs?
    10·1 answer
  • The Software Engineering Code of Ethics and Professional Practice was developed by Select one: a. Computer Professionals for Soc
    7·1 answer
  • Discuss TWO changes in ICMP that took place with the development of IPV6 and indicate why those changes were made.
    7·1 answer
  • What is the purpose of extent in lines in engineering drawing
    12·1 answer
  • Does anyone have Rblx? if so write your username
    6·1 answer
  • Indicate if the statement is true or false False 1. A spreadsheet cannot recalculate after you have changed data in your workshe
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!