Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 6.2, Problem 21STE
(This exercise is for those who have studied the optional section entitled “File Names as Input.”) Suppose you are given the following string variable declaration and input Statement:
#include <iostream>
using namespace std;
// ... char name[21];
cout >> name;
Suppose this code segment is embedded in a correct
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In Python,
Use the file scores.txt (below) to help with the coding problem.!
scores.txt
———————
John
-3
Paul
3
Sue
2
——————-
utilize the follow function headers:
Main()
WriteScores()
ReadScores()
First, the main function will ask the user, “do you want to record scores or read scores?” Depending on what the user inputs, the answer will determine whether to call WriteScores OR ReadScores. The WriteScores function will then ask the user, “how many scores do you want to add?”. The function will then read each of the players name and score as keyboard input, then save these as records in a file named scores.txt.
Sample output:
Do you want to read scores or write scores?
Type r or w: r
Name: John
Golf Score: -2
Name: Paul
Golf Score: -1
Name: George
Golf Score: - 4
Practice problem we were given in C++ to review for test. Thanks
Write a program that reads data from a data file, the value of which is provided at the end of the problem. Your program is to incorporate the following requirements:
Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file.
Save the output of the program in a file.
Write a function called getNumber which reads a number from the input file, outputs the number to the output file and the monitor and sends the input number to the function main. Make sure, both input and out file are being opened in the main program.
Write a function called classifyNumber which counts number of even, odd, and zero (occurrences of zero) available in the input file.
Have the program find the sum and average of the numbers and print only 10 numbers per line.
Write a function called printResult so that it outputs (in output file and monitor) even number of…
I need help in creating a C function that will read a specific line from a text file in C based on the randomly generated number ranging from 1 to 50. The function would have the parameter of the text file and would return the string that the specific line of the text file contains. Note(the text file only contains characters , sentences and no numbers)
Restrictions : Cant use break, exit(), break , continue,global variables. Only allowed to use stdio.h and string.h
For instance if the random number is 4 then the function would return the 4th line of the particular text file.
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...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Briefly describe what each of the following statements does. file.seekp(100L, ios::beg); file.seekp(-10L, ios::...
Starting Out with C++: Early Objects
Why is it necessary to introduce some methods and documentation from plan-based approaches when scaling agile m...
Software Engineering (10th Edition)
Given the following fragment that purports to convert from degrees Celsius to degrees Fahrenheit, answer the fo...
Absolute Java (6th Edition)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
What is the purpose of an objects sizing handles?
Starting Out With Visual Basic (7th Edition)
Is it possible to pass initialization values to the constructor when you create an object? If so, how?
Starting out with Visual C# (4th Edition)
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
- In Python, Use the file scores.txt (below) to help with the coding problem.! name.txt ——————— John -3 Paul 3 Sue 2 ——————- utilize the follow function headers: Main() WriteScores() ReadScores() First, the main function will ask the user, “do you want to record scores or read scores?” Depending on what the user inputs, the answer will determine whether to call WriteScores OR ReadScores. The WriteScores function will then ask the user, “how many scores do you want to add?”. The function will then read each of the players name and score as keyboard input, then save these as records in a file named scores.txt. Sample output: Do you want to read scores or write scores? Type r or w: r Name: John Golf Score: -2 Name: Paul Golf Score: -1 Name: George Golf Score: - 4arrow_forwardI have a text file and I want to read it in C++. variables to use: fname, lname , Id nr, Gender and all third line which is an address . Note: *** The result in your program should be written to a new file. So you need to open 2 files in your program, one for reading and one for writing. The file is : Tommy James 23456731667 Streetname 45 , 154 23 Georgia John Andersson 3456723464 Streetname 12 , 231 32 Las Vegas Kim Larsson 3456312653 Streetnamn 15, 231 56 Florida If we Said the 8th digit in ID number is showing the Gender of the person. By %2== 0 it's Male The output should be: Lname Fname [F] address Is there possible to create a program in C++ with the previously output. lname , fname [F]Adress Without have a problem with Las Vegas word. I have a hard time to figure how I can do the third line in the file. They read to word Las and then the compiler shows terminate called after throwing an instance of ' std::invalid_ argument ' what (): stoi aborted so I figured…arrow_forwardThe goal for this question: DISCLAIMER****** CODE MUST BE WRITTEN IN C CODE. NOT C++, C#, etc. To create a program that MUST utilize the functions (argc, argv, char strstr, and possibly even Getline) to, 1. Open a file 2. Read the file 3. Read txt file line by line 4. count up the number of times a specified word is read(HOWEVER! IT CANNOT COUNT MORE THAN ONE WORD PER LINE!) ex. if the code comes across a line in a text file that has the word cookie in it 3 times. It can only count the word ONCE since it is counting line by line. Not all the words added up. 5. then display to the user the total number of lines with the specific word. ex. gcc -o <program name> ./<program name> <file name.txt> <"word to be searched"> then execute a total number of times words came up. Again, only count up by one even if there is that specified word multiple times in one line.arrow_forward
- I need help in creating a C function that will read a specific line from a text file in C based on the randomly generated number ranging from 1 to 50(have to use rand() ). The function would have the parameter of the text file and would return the string that the specific line of the text file contains. Restrictions : Cant use break, exit(), break , continue,global variables. Only allowed to use stdio.h and string.h For instance if the random number is 4 then the function would return the 4th line of the particular text file.arrow_forward1)_Modify the code to fix the buffer overflow problem by using a safe C function instead of the unsafe gets() and using some C function to compare the strings. Hints: fgets() or scanf(), strncmp(), strlen(). For scanf(), you would have to use format specifiers to specify the width of the string for the output. 2) Your modified program should display an output “wrong password” for each of the following four cases: Case 1: input password = "by". (User input is half that of given password text) Case 2: input password = "bytebyte". (User input is twice that of given password text) Case 3: input password = "1234". (User input is a garbage text of same length) Case 4: input password = "12345678901234567890". (User input is a garbage text which is longer than the given password) the code : #include <stdio.h>#include <string.h>#include <stdlib.h>int main(void) {// Use a struct to force local variable memory orderingstruct {char buff[5];char pass;}…arrow_forwardIn C++, my program reads from a file, each line of the text file ends in a 1 or 0. How do you make a function that updates the value in the text file to change to from 1 to 0 or 0 to 1?arrow_forward
- Hello good afternoon, Write a C++ program that reads data from an input file, takes the data and computes student grades for an assignment by converting the raw score to a percentage given each student's score and the total points. The final score must be rounded up to the nearest whole value using the ceil function in the header file and displayed as a percentage. You must also display the floating-point result up to 5 decimal places. You must use at least 2 functions: one to print the last name of the student and another function to compute and print the percentage as well as "Excellent" if the grade is greater than 90, "Well Done" if the grade is greater than 80, "Good" if the grade is greater than 70, "Need Improvement" if the grade is greater than or equal to 60, and "Fail" if the grade is less than 50. The main function is responsible for reading the input file and passing the appropriate arguments to your functions.arrow_forward2. Write a complete C program that inputs marks of a student in 5 courses using any loop and writes these marks into an output file named myElements.txt. After that, it reads scores from myElements.txt and computes the grades based on the table below using a programmer-defined function char computeGrade(double score), and displays the grades on screen. - please, write the c program code and include comments on your code, contents of the file myElements.txt , and sample output. Thank you so much.arrow_forwardYou are required to make changes in the below programs and introduce the use of compaction where required. #include<stdio.h> #include<conio.h> main() { int ms, bs, nob, ef,n, mp[10],tif=0; int i,p=0; clrscr(); printf("Enter the total memory available (in Bytes) -- "); scanf("%d",&ms); printf("Enter the block size (in Bytes) -- "); scanf("%d", &bs); nob=ms/bs; ef=ms - nob*bs; printf("\nEnter the number of processes -- "); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter memory required for process %d (in Bytes)-- ",i+1); scanf("%d",&mp[i]); } printf("\nNo. of Blocks available in memory -- %d",nob); printf("\n\nPROCESS\tMEMORY REQUIRED\t ALLOCATED\tINTERNAL FRAGMENTATION"); for(i=0;i<n && p<nob;i++) { printf("\n %d\t\t%d",i+1,mp[i]); if(mp[i] > bs) printf("\t\tNO\t\t---"); else { printf("\t\tYES\t%d",bs-mp[i]);tif = tif + bs-mp[i]; p++; } } if(i<n) printf("\nMemory is Full, Remaining Processes cannot be accomodated"); printf("\n\nTotal…arrow_forward
- How do I create a function in C++ that takes in a file name, ie. data.txt, on input and reads the data contained in the file and prints to screen the most frequently occurring integer in the file. Also, if two or more of the most frequently occurring integers occur equally often, it should return the largest.arrow_forward8. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 5; float b; cout << sizeof(++a + b); cout << a; return 0; }arrow_forwardHi, in C programming , I try to implement 2 functions to check those followings instructions in a file text : The first function :Find the number of words with duplicates on a file The second function: • Find the most frequent letter (without considering duplicates) Finally write those results on another file. Thanksarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C - File I/O; Author: Tutorials Point (India) Ltd.;https://www.youtube.com/watch?v=cEfuwpbGi1k;License: Standard YouTube License, CC-BY
file handling functions in c | fprintf, fscanf, fread, fwrite |; Author: Education 4u;https://www.youtube.com/watch?v=aqeXS1bJihA;License: Standard Youtube License