Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 6, Problem 7P
Program Plan Intro
Creation of
Program Plan:
- Define a function “Function()” to sort and merge values in files.
- Compare values in both input files.
- Compare first two elements and write the smallest element to output file first followed by the other one.
- Continue the process until all elements are been compared in both lists.
- Compare values in both input files.
- Define a main method.
- Declare variables required for program.
- Get file names for input and output files from the user.
- Call method “Function()” to sort and merge values in files.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a Python program that calculates the average 5 quiz scores from a file with student ID and scores.
Your program must have 2 functions; the main and calculateAvg-
The main function reads data from an input file, which has the format shown below. Each line in the file
starts with the Student ID followed by 5 values representing the scores attained by the Student in 5
quizzes.
For each Student, the calculateAvg function receives a list containing the 5 values and returns another
list containing all the values in the original list plus the average score of the quizzes for each student.
This information will be written in an output file as shown below.
Also, you must include the class average at the end. Which includes all the students in the list.
Note:
You program must be general and works for any number of Students.
All reading and writing must be done in the main function.
Assume each student has 5 quiz scores
Input text file name must be grades.txt
Output text file name must be…
The file text.txt contains a sentence text written in all small letters and does
not have any punctuation marks, no numbers, no symbols except for spaces.
You are required to write a program which accepts an operation code, and
zero to two inputs depending on the operation code. Based on the operation
code, you will call three versions of the overlaoded function textProcessing as
follows:
●
Operation 0: The function removes all vowels from the ORIGINAL
sentence. The vowels considered are the small letters (a, e, i, o, u y, and
w).
• Operation 1: The code further asks for one lowercase letter to be input
by the user. If the character is not a lower case letter, the code outputs
Invalid.The function returns the distance (difference) between the
letter first occurence and last occurence in the text. If the letter does
not occur in the sentence, it returns 0.
• Operation 2: The code asks for two lowercase letters to be input by the
user. If the characters are not lower case letters, the…
Write a python program that will open a file and place each line of text from the file into a Python list. This program will calculate total number of lines, words and characters in the file. Write a python function counter to calculate and return total number of lines, words and characters in a text (.txt) file. The count function needs to return total number of lines, words and characters from the function.
Also the function will take two parameters: • fileName is the name of the file that need to be opened to calculate the file stats (# of lines, # of words and # of characters). • lineList – this is python list that contains that will add each line (strip of new line feed in the line) to the python list.
#function count will open the file fileName and counts how many lines, words and chars # in the file, and place each line of the file in the lineList parameter. # The function must RETURN numOfLine, numOfWords, numOfChars as return value, # and lineList as parameter # # numOfLine:…
Chapter 6 Solutions
Problem Solving with C++ (10th Edition)
Ch. 6.1 - Prob. 1STECh. 6.1 - Prob. 2STECh. 6.1 - Suppose that you are still writing the same...Ch. 6.1 - Prob. 4STECh. 6.1 - Prob. 5STECh. 6.1 - Prob. 6STECh. 6.1 - Suppose bla is an object, dobedo is a member...Ch. 6.1 - Prob. 8STECh. 6.1 - Prob. 9STECh. 6.1 - A program has read half of the lines in a file....
Ch. 6.1 - Prob. 11STECh. 6.2 - Prob. 12STECh. 6.2 - Prob. 13STECh. 6.2 - Prob. 14STECh. 6.2 - What output will be sent to the stuff.dat when the...Ch. 6.2 - Prob. 16STECh. 6.2 - In formatting output, the following flag constants...Ch. 6.2 - Here is a code segment that reads input from...Ch. 6.2 - Prob. 19STECh. 6.2 - Write the definition for a void function called...Ch. 6.2 - (This exercise is for those who have studied the...Ch. 6.3 - Suppose c is a variable of type char. What is the...Ch. 6.3 - Suppose c is a variable of type char. What is the...Ch. 6.3 - Prob. 24STECh. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Suppose that the program described in Self-Test...Ch. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Prob. 29STECh. 6.3 - Define a function called copyLine that takes one...Ch. 6.3 - Prob. 31STECh. 6.3 - (This exercise is for those who have studied the...Ch. 6.3 - (This exercise is for those who have studied the...Ch. 6.3 - Suppose ins is a file input stream that has been...Ch. 6.3 - Write the definition for a void function called...Ch. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Write some C++ code that will read a line of text...Ch. 6 - Write a program that will search a file of numbers...Ch. 6 - Write a program that takes its input from a file...Ch. 6 - a. Compute the median of a data file. The median...Ch. 6 - Write a program that takes its input from a file...Ch. 6 - Write a program that gives and takes advice on...Ch. 6 - Write a program that reads text from one file and...Ch. 6 - Prob. 7PCh. 6 - Write a program to generate personalized junk...Ch. 6 - Write a program to compute numeric grades for a...Ch. 6 - Enhance the program you wrote for Programming...Ch. 6 - Prob. 4PPCh. 6 - Write a program that will correct a C++ program...Ch. 6 - Write a program that allows the user to type in...Ch. 6 - This project is the same as Programming Project 6,...Ch. 6 - This program numbers the lines found in a text...Ch. 6 - Write a program that computes all of the following...Ch. 6 - The text file babynames2012.txt, which is included...Ch. 6 - To complete this problem you must have a computer...Ch. 6 - Write a program that prompts the user to input the...Ch. 6 - The following is an old word puzzle: Name a common...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- You are given a file consisting of students’ names in the following form: lastName, firstName middleName. (Note that a student may not have a middle name.) Write a program that converts each name to the following form: firstName middleName lastName. Your program must read each student’s entire name in a variable and must consist of a function that takes as input a string, consists of a student’s name, and returns the string consisting of the altered name. Use the string function find to find the index of ,; the function length to find the length of the string; and the function substr to extract the firstName, middleName, and lastName.arrow_forwardComplete a C++ program that reads from a file named fruits.txt which contains a list of fruits. First, the fruits should be read into an array. Then, your program should ask the user for a specific fruit to search. If the word is in the list of words, the program should return “Fruit located at index: X” where the X is the index of the array where the fruit is located. If the fruit is not in the array, your program should return “I didn’t find the fruit!”. This message should only print once at the very end if the fruit is not found. If there is an error opening the file, your program should print an error message. If the fruit you are looking for is in the array in multiple locations, your program only needs to print one of the indexes. The following presents a sample words.txt and execution result. fruits.txt 6 apple carrot banana date grape fig in c++ programingarrow_forwardIn a text file, I have two numbers each line. The numbers are the employee ID and the number of hours the employee work. My goal of this program is to read the both employee ID and the number of hours the employee work and print it out in the main program. If the list of employee id is not in order, sort it in order and still print it out in the main program. Additionally, after printing them out, print out the total number of employees and the total number of hours all the employee work. Write this in java For example File.txt EmployeeID Number of Hours Work 3 12 2 20 1 40 5 20 7 9 In the main program print: EmployeeID Number of Hours Work 1 40 2 20 3 12 5 20 7 9arrow_forward
- Design a program that reads a file called sales.txt containing the following data: Jane, 215.5,445.5,910.0 John, 825.0,250.5,675.0 Bill,0.0,999.15 Each line has a employee's name and their weekly sales totals all separated by commas. Some employees have taken vacation some weeks so no numbers are captured for those weeks. Create a function that takes a list of floats and returns the average value for those numbers. After reading the information from the file, use a for loop to calculate the sales average using your new average function for each employee and display the following output to the screen. Jane, average sales: 523.67 John, average sales: 583.50 Bill, average sales: 499.56arrow_forwardGiven a file with data for names and marks you will read them into two arrays You will then display the data, do a linear search and report if found, sort the data, do a binary search. Be sure to test for found and not found in your main program. Read Data Write a function that reads in data from a file using the prototype below. The function can define and open the file, read the names and marks into the arrays and keep track of how many names there are in numElts, and then closes the file. The list of names and marks can be found at the end of the lab and copied into a text file. void getNames(string names[], int marks[], int& numElts); Display Data Write a function to display the contents of names and marks using the prototype given below. void displayData(const string names[], const int marks[], int numElts); Linear Search Write the searchList function given the prototype below so that it searches for a given name. The functions returns and int which is the…arrow_forwardGiven a file with data for names and marks you will read them into two arrays You will then display the data, do a linear search and report if found, sort the data, do a binary search. Be sure to test for found and not found in your main program. Read Data Write a function that reads in data from a file using the prototype below. The function can define and open the file, read the names and marks into the arrays and keep track of how many names there are in numElts, and then closes the file. The list of names and marks can be found at the end of the lab and copied into a text file. void getNames(string names[], int marks[], int& numElts); Display Data Write a function to display the contents of names and marks using the prototype given below. void displayData(const string names[], const int marks[], int numElts); Linear Search Write the searchList function given the prototype below so that it searches for a given name. The functions returns and int which is…arrow_forward
- Given a text file containing the availability of food items, write a program that reads the information from the text file and outputs the available food items. The program first reads the name of the text file from the user. The program then reads the text file, stores the information into four separate arrays, and outputs the available food items in the following format: name (category) -- description Assume the text file contains the category, name, description, and availability of at least one food item, separated by a tab character. Ex: If the input of the program is: food.txt and the contents of food.txt are: Sandwiches Ham sandwich Classic ham sandwich Available Sandwiches Chicken salad sandwich Chicken salad sandwich Not available Sandwiches Cheeseburger Classic cheeseburger Not available Salads Caesar salad Chunks of romaine heart lettuce dressed with lemon juice Available Salads Asian salad Mixed greens with ginger dressing, sprinkled with sesame Not available Drinks Water…arrow_forwardGiven a text file containing the availability of food items, write a program that reads the information from the text file and outputs the available food items. The program first reads the name of the text file from the user. The program then reads the text file, stores the information into four separate arrays, and outputs the available food items in the following format: name (category) -- description Assume the text file contains the category, name, description, and availability of at least one food item, separated by a tab character. Ex: If the input of the program is: food.txt and the contents of food.txt are: Sandwiches Ham sandwich Classic ham sandwich Available Sandwiches Chicken salad sandwich Chicken salad sandwich Not available Sandwiches Cheeseburger Classic cheeseburger Not available Salads Caesar salad Chunks of romaine heart lettuce dressed with lemon juice Available Salads Asian salad Mixed greens with ginger dressing, sprinkled with sesame Not available Drinks Water…arrow_forwardWrite a function that reads all the numbers from a file into an array. The file is already open and there is no bad data in the file. The data is one number per line and the file has an unknown number of lines of data. Assume that the array is large enough to hold all the data. The data should be stored in the array starting at the first element. Prototype void readData( ifstream& iFile, double numbers[ ], int& count); iFile - already open ifstream numbers[ ] - array to store data count - the number of values read and must be set by the function before returning.arrow_forward
- In C languagearrow_forwardPlease use Python for this question. Please format code properly when answering the question. Write a standalone function partyVolume() that takes accepts one argument, a string containing the name of a file. The objective of the function is to determine the Volume object that is the result of many people at a party turning the Volume up and down. More specifically: the first line of the file is a number that indicates the initial value of a Volume The remaining lines consist of a single character followed by a space followed by a number. The character will be one of ‘U” or ‘D’ which stand for “up” and “down” respectively. The function will create a new Volume object and then process each line of the file by calling the appropriate method of the Volume object which changes the value of the Volume. The function then returns the final Volume object. Guidelines/hints: This is a standalone function, it should NOT be inside (indented within) the class. It should be listed in…arrow_forwardComputer Science Write a program that uses 3 command line arguments to search a list of float numbers in a file and prints out the result of whether the number was found or not on the console. Also, it prints the array in the reverse order (not sorted but reverse order of how the numbers were read in). The first argument is the name of the input file which has the numbers to be searched, the second is an integer specifying how many numbers are in the input file and the third argument is the float number being searched for. Use dynamic memory allocation for the array and use a function (that returns a boolean value) to do the searching. Also make sure in the beginning of your program, that the program will execute only if exactly three arguments (other than executable name itself) are specified. at the command line.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr