Welcome to Assignments Writing

Your Trusted Partner in Term Paper Writing

At Assignments Writing, we’re a team of passionate educators and skilled writers committed to supporting students in their academic journey.

Computer science programan solving C Plus Plus Questions

Computer science programan solving C Plus Plus Questions

ANSWER

Here’s a Python program that implements the described functionality. It reads a file, allows the user to modify its content, and writes the modifications back to the same file:

python
import os

# Function to display the menu and current list
def display_menu(active, numbers):
print("Menu:")
print("1. Insert")
print("2. Delete")
print("3. Sort")
print("4. Select")
print("5. Move Right")
print("6. Move Left")
print("7. Exit")
print("\nCurrent List:", numbers)
print("Active Item:", active)

# Function to load the file content into memory
def load_file(file_name):
try:
with open(file_name, 'r') as file:
active = int(file.readline().strip())
numbers = list(map(int, file.readline().strip().split()))
return active, numbers
except FileNotFoundError:
# File doesn't exist, initialize with default values
return 0, []

# Function to save the content back to the file
def save_file(file_name, active, numbers):
with open(file_name, 'w') as file:
file.write(str(active) + '\n')
file.write(' '.join(map(str, numbers)))

# Function to insert an integer before the selected item
def insert_item(active, numbers):
if len(numbers) < 10:
try:
new_number = int(input("Enter the integer to insert: "))
numbers.insert(active, new_number)
return active, numbers
except ValueError:
print("Invalid input. Please enter a valid integer.")
else:
print("List is full. Insertion not possible.")
return active, numbers

# Function to delete the active item
def delete_item(active, numbers):
if len(numbers) > 0:
del numbers[active]
if active >= len(numbers):
active = len(numbers) - 1
else:
print("List is empty. Deletion not possible.")
return active, numbers

# Function to sort the list in ascending order
def sort_list(active, numbers):
numbers.sort()
return active, numbers

# Function to select the next item in the list
def select_next(active, numbers):
if len(numbers) > 0:
active = (active + 1) % len(numbers)
return active, numbers

# Function to move the selected item one position to the right
def move_right(active, numbers):
if active < len(numbers) - 1:
numbers[active], numbers[active + 1] = numbers[active + 1], numbers[active]
active += 1
else:
print("Cannot move right. Last item is selected.")
return active, numbers

# Function to move the selected item one position to the left
def move_left(active, numbers):
if active > 0:
numbers[active], numbers[active - 1] = numbers[active - 1], numbers[active]
active -= 1
else:
print("Cannot move left. First item is selected.")
return active, numbers

if __name__ == "__main__":
file_name = "data.txt"
active, numbers = load_file(file_name)

while True:
os.system('clear' if os.name == 'posix' else 'cls')
display_menu(active, numbers)
choice = input("Enter your choice: ")

if choice == "1" or choice.lower() == "insert":
active, numbers = insert_item(active, numbers)
elif choice == "2" or choice.lower() == "delete":
active, numbers = delete_item(active, numbers)
elif choice == "3" or choice.lower() == "sort":
active, numbers = sort_list(active, numbers)
elif choice == "4" or choice.lower() == "select":
active, numbers = select_next(active, numbers)
elif choice == "5" or choice.lower() == "move right":
active, numbers = move_right(active, numbers)
elif choice == "6" or choice.lower() == "move left":
active, numbers = move_left(active, numbers)
elif choice == "7" or choice.lower() == "exit":
save_file(file_name, active, numbers)
break
else:
print("Invalid choice. Please enter a valid option.")

print("Goodbye!")

This program uses functions to separate different tasks, such as loading and saving the file, displaying the menu, and performing various operations on the list of integers. It should meet the requirements outlined in your description.

Computer science programan solving C Plus Plus Questions

QUESTION

Description

 

 

Your goal is to implement an application that reads a file, modify its content, and writes the modification back to the same file. The file includes 2 lines of integers. The first line indicates which integer on the second line has been selected (active). And the second line lists all the integers (maximum of 10).

Your application should have a menu that is constantly displayed on the screen (see the menu below). Right below the menu, the program should display list of all integers in the file (second line). Also it should show which integer is currently selected (active).
The user should be able to select a menu item by entering its associated key or by pressing one of the indicated extended keys on the keyboard.
“Insert” will insert an integer before the selected item and makes the newly inserted item active. The integer is typed by the user. If the list is full, insertion will not be possible. Do not accept incorrect values.
“Delete” deletes the active item.
“Sort” sorts the list in ascending order. The active item after the sort is same as the active item before the sort.

“Select” selects the next item in the list. If the last item is selected, this option selects the first item in the list.
“Move Right” moves the selected item one position to right. If the last item is selected, moving right will not be possible.

“Move Left” moves the selected item one position to left. If the first item is selected, moving left will not be possible.

“Exit” ends the application.

Make sure to use the top-down design to break your program to many simpler tasks (at least one function per task). Do not use global variables. Make sure to check the special cases. Example: list is full or list is empty. Your program should copy the content of the file into an array and a variable when you start the program. The program write back the content of the array and the variable into the file when you exit the program. When you are using the program, you should modify the array and variables and not the file. Do not forget to add comments.

Menu:

Insert “1” or “Insert” key
Delete “2” or “Delete” key
Sort “3” or “F2” key
Select “4” or “Down Arrow” key
Move Right. “5” or “Page Down” key
Move Left. “6” or “Page Up” keyExit “7” or “F1” key

Place Your Order Here

Our Service Charter


1. Professional & Expert Writers: We only hire the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of master’s and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. We are known for timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: We have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

Format & Features

Our Advantages

How It Works

1. Fill Order Form
2. Make payment
3. Writing process
4. Download paper

Fill in the order form and submit all your files, including instructions, rubrics, and other information given to you by your instructor.

Once you complete filling the forms, complete your payment. We will get the order and assign it to a writer.

When your order is completed, it’s assigned to an editor for approval. The editor approves the order.

Once approved, we will upload the order to your account for you to download.  You can rate your writer or give your customer review.

What Clients Said

{

I am very satisfied! thank you for the quick turnaround. I am very satisfied! thank you for the quick turnaround.I am very satisfied! thank you for the quick turnaround.

5
Mercy M
{

I am very satisfied! thank you for the quick turnaround. I am very satisfied! thank you for the quick turnaround.I am very satisfied! thank you for the quick turnaround.

5
Jane L
{

I am very satisfied! thank you for the quick turnaround. I am very satisfied! thank you for the quick turnaround.I am very satisfied! thank you for the quick turnaround.

4.5
Rayan M

LET US DELIVER YOUR ACADEMIC PAPER ON TIME!

We are a freelance academic writing company geared towards provision of high quality academic papers to students worldwide.

Open chat
1
Scan the code
Hello
Can we help you?