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
At the end of this and other textbooks, there usually is an index that lists the pages where a certain word appears. In this problem, you will create an index for a text but, instead of page number, you will use the line numbers.
You will implement function index() that takes as input the name of a text file and a list of words. For every word in the list, your function will find the lines in the text file where the word occurs and print the corresponding line numbers (where the numbering starts at 1). You should open and read the file only once
Create the python function as part of a python program. The data required for the function should be created in the python program and passed to the function.
its an exercise pyrthon problem 6.27
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…
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
- 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:…arrow_forwardWrite a program that creates a function to read multiple DNA sequences from the user and writes them in “Sequence.txt” file. Create another function that takes a string of DNA as argument and returns its transcribed sequence. Now read each sequence from Sequence.txt file, transcribe it, calculate its length & nucleotides frequencies. Store this modified information in a formatted way in another file named as “ModifiedSequences.txt”. In the end display contents of both the files. ***coding language python use bio python necessarily for solving this question***don't use arrays or pointers keep the program as basic as possible*** paste the scereenshots of input and output and also copy paste the program Write comments on each and every line of programarrow_forwardWrite a program that creates a function to read multiple DNA sequences from the user and writes them in “Sequence.txt” file. Create another function that takes a string of DNA as argument and returns its transcribed sequence. Now read each sequence from Sequence.txt file, transcribe it, calculate its length & nucleotides frequencies. Store this modified information in a formatted way in another file named as “ModifiedSequences.txt”. In the end display contents of both the files. (did it in python)arrow_forward
- You are to write a program that will read a text file, echo it to the screen, and create an array of the words in the file. When the program terminates, it should produce a list of the words encountered. and the number of times each word occurred (this information is to be stored in the array). The ordering of that list should be based on the order in which the words first occurred in the original text file, with one word per line. Format the output line as: Word Count See 14 Spot 4 Run 25 You may assume the following simplifying characteristics concerning the text file. The punctuation in the file consists only of periods, question marks, exclamation marks, and commas. There are 2 blanks following each period, exclamation mark, or question mark, followed by the first letter of the next sentence. The two blanks will be omitted if the delimiter terminates a line. There…arrow_forwardProgramarrow_forwardYou 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_forward
- Complete 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_forwardWrite a C++ program that reads first name and last name from two txt files, input1.txt and input2.txt respectively and stores them in two separate arrays. Then merges these two arrays into another txt file output.txt. Example: Intput1.txt: Markus Input2.txt: Stocker Output.txt: Markus Stockerarrow_forwardWrite a C++ program that reads a list of numbers from a file into an array, then uses that array to find the average of all the numbers, the average of the positive and negative numbers (0 is neither positive nor negative!), and the largest number. The point is to be able to store data in an array and do things with it Your program must contain at least the following four functions... read_list() This function will take as input parameters an array of integers and a string filename. It will open that file and read in numbers, storing them in the array, stopping at the end of the file. Remember that there are tricky issues with extra whitespace at the end of the file. You can assume the file contains only integers. The function will return the number of numbers that were read in.Note: In versions of Visual C++ pre-2010, when using the open function with a string argument, you must call the c_str() function on the string variable, such as:my_input_stream.open( filename.c_str() ) 2.…arrow_forward
- C++ A teacher is requiring her students to line up in alphabetical order, according to their first names..For example, in one class Chapel, Christine would be at the front and Uhura, Nyota would be last. The program will get the names from a file. The names should be read in until there is no more data to read. The program should prompt the user for the file name and read the data from the file. A suitable file of names (List of Random Names) is provided on Moodle. Note that these names might include spaces; handle your input accordingly. The expected output is two names; do not show the entire file (or you will regret that code when you do the associated programming quiz that processes thousands of names). Do not use arrays or sorting for this problem.arrow_forwardWrite a write_scores function that opens the file, and writes scores and names from lst_scores and lst_names into the file. An example function call is below. Make sure to handle a file error. Assume good input in both lists. Function name: write_scoresParameters: lst_scores, a list of ints; lst_names, a list of strings; file_name, a string Purpose: Writes the names and scores to the file name, with one name and one corresponding score per line.Example function call: (attached) After this code runs, the file final_grades.txt should read: Ayesha 96 Paolo 99 Ahmed 93 Anna 94arrow_forwardPlease write a complete C++ programarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education