Starting Out with C++
8th Edition
ISBN: 9780133888201
Author: GADDIS
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 12.5, Problem 12.9CP
What will be stored in the file out.txt after the following
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
const int SIZE = 5;
ofstrean outFile(“out.txt”);
double nums[SIZE] = {100.279, 1.719, 8.602, 7.777, 5.099};
outFile << fixed << setprecision(2);
for (int count = 0; count < 5; count++)
{
outFile << setw(8) << nums[count];
}
outFile.close();
return 0;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
DataFile.txt contains the information of poker cards. 1. C: clubs (lowest), D: diamonds, H: hearts, S: spades (highest) 2. 2 (lowest), 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A 3. No Joker cards 4. Any C cards are lower than any D cards.
DataFile Content (You can write the file specification into your program.) : H4,C8,HJ,C9,D10,D5,DK,D2,S7,DJ,H3,H6,S10,HK,DQ,C2,CJ,C4,CQ,D8,C3,SA,S2,HQ,S8, C6,D9,S3,SQ,C5,S4,H5,SJ,D3,H8,CK,S6,D7,S9,H2,CA,C7,H7,DA,D4,H9,D6,HA,H10,S5,C10 H4, D5, HK, D2 H4, HK, SK C9,C10 1. Create a list by dynamic allocated array and set the size to 20 2. Read the first 20 cards in the first line of the file, the put them one by one into the list by implementing and using putItem(). The list must be kept sorted in ascending order. Then print out all the cards in the list in one line separating by commas. 3. Then delete the cards indicated in the second line of the file by using deleteItem() Then print out all the cards in the list in one line separating by commas. 4. Then put…
Files in C Language
Assume that “GO.TXT” exists with a file size of 2KB. What is new file size of “GO.TXT” in bytes after executing the following code segment successfully?
char s[ 255 ] = "SOCIAL DISTANCING"; // there is one space between SOCIAL and DISTANCINGfp = fopen("GO.TXT", "a"); fprintf(fp, "%s", s);fclose(fp);
Python Code:
Below is an open link to file needed in this program
Spots: https://drive.google.com/file/d/1uaqwxYYn4AHJlFB0ukxm3PD8ISoakz6F/view?usp=sharing
libraries numpy as np and matplotlib.pyplot as plt must be imported and then used.
Write a program which reads the data from the file spots.txt (linked above), and then calculates the mean, median, mode and standard deviation of the data.
Using the above information, the program should then plot a histogram of the number of sunspots/month distributed over 50 bins.
Use the plt.hist() function to help you with this.
Chapter 12 Solutions
Starting Out with C++
Ch. 12.1 - Which file access flag would you use if you want...Ch. 12.1 - Prob. 12.2CPCh. 12.1 - Assuming diskInfo is an fstream object, write a...Ch. 12.1 - Assuming diskInfo is an fstream object, write a...Ch. 12.1 - Assuming diskInfo is an fstream object, write a...Ch. 12.1 - Write a statement that defines an fstream object...Ch. 12.5 - Assume the file input.txt contains the following...Ch. 12.5 - Describe the difference between reading a file...Ch. 12.5 - What will be stored in the file out.txt after the...Ch. 12.10 - Describe the difference between the seekg and the...
Ch. 12.10 - Describe the difference between the tellg and the...Ch. 12.10 - Describe the meaning of the following file access...Ch. 12.10 - What is the number of the first byte in a file?Ch. 12.10 - Briefly describe what each of the following...Ch. 12.10 - Describe the mode that each of the following...Ch. 12 - What capability does the fstream data type provide...Ch. 12 - Which file access flag do you use to open a file...Ch. 12 - Assume the file data.txt already exists, and the...Ch. 12 - How do you combine multiple file access flags when...Ch. 12 - Should file stream objects be passed to functions...Ch. 12 - Under what circumstances is a file stream objects...Ch. 12 - Under what circumstances is a file stream objects...Ch. 12 - Under what circumstances is a file stream objects...Ch. 12 - How do you read the contents of a text file that...Ch. 12 - What arguments do you pass to a file stream...Ch. 12 - What arguments do you pass to a file stream...Ch. 12 - Prob. 12RQECh. 12 - Prob. 13RQECh. 12 - How do you get the byte number of a files current...Ch. 12 - If a program has read to the end of a file, what...Ch. 12 - How do you determine the number of bytes that a...Ch. 12 - How do you rewind a sequential-access file?Ch. 12 - The _____ file stream data type is for output...Ch. 12 - If a file fails to open, the file stream object...Ch. 12 - The same formatting techniques used with...Ch. 12 - The _____ function reads a line of text from a...Ch. 12 - The ____________ member function reads a single...Ch. 12 - The ________member function writes a single...Ch. 12 - Prob. 24RQECh. 12 - __________ files contain data formatted as...Ch. 12 - Prob. 26RQECh. 12 - Prob. 27RQECh. 12 - The ___________ member function writes raw binary...Ch. 12 - The __________ member function reads raw binary...Ch. 12 - Prob. 30RQECh. 12 - In ___________ file access, the contents of the...Ch. 12 - In __________ file access, the contents of a file...Ch. 12 - The _____________ member function moves a files...Ch. 12 - The ___________ member function moves a files...Ch. 12 - The __________ member function returns a files...Ch. 12 - The ___________ member function returns a files...Ch. 12 - The __________ mode flag causes an offset to be...Ch. 12 - The __________ mode flag causes an offset to be...Ch. 12 - The ________ mode flag causes an offset to be...Ch. 12 - A negative offset causes the files read or write...Ch. 12 - Write a statement that defines a file stream...Ch. 12 - Write two statements that use a file stream object...Ch. 12 - Write two statements that use a file stream object...Ch. 12 - Write two statements that use a file stream object...Ch. 12 - Write a program segment that defines a file stream...Ch. 12 - Write code that opens the file data.txt for both...Ch. 12 - Write code that determines the number of bytes...Ch. 12 - The infoFile file stream object is used to...Ch. 12 - T F Different operating systems have different...Ch. 12 - T F fstream objects are only capable of performing...Ch. 12 - T F ofstream objects, by default, delete the...Ch. 12 - T F ifstream objects, by default, create a file if...Ch. 12 - T F Several file access flags may be joined by...Ch. 12 - T F A file may be opened in the definition of the...Ch. 12 - T F If a file is opened in the definition of the...Ch. 12 - T F A file stream objects fail member function may...Ch. 12 - T F The same output formatting techniques used...Ch. 12 - T F The operator expects data to be delimited by...Ch. 12 - T F The getline member function can be used to...Ch. 12 - T F It is not possible to have more than one file...Ch. 12 - T F Binary files contain unformatted data, not...Ch. 12 - T F Binary is the default mode in which files are...Ch. 12 - T F The tellp member function tells a file stream...Ch. 12 - T F It is possible to open a file for both input...Ch. 12 - fstream file(ios::in | ios::out);...Ch. 12 - ofstream file; file.open (info.dat, ios::tin); if...Ch. 12 - fstream file("info.dat"); if (!file) { cout ...Ch. 12 - fstream dataFile("info.dat", ios:in | ios:binary);...Ch. 12 - Prob. 69RQECh. 12 - fstream dataFi1e("info.dat", ios:in); char...Ch. 12 - Prob. 71RQECh. 12 - fstream inFile("info.dat", ios:in); int x;...Ch. 12 - File Head Program Write a program that asks the...Ch. 12 - File Display Program Write a program that asks the...Ch. 12 - Punch Line Write a program that reads and prints a...Ch. 12 - Tail Program Write a program that asks the user...Ch. 12 - Line Numbers (This assignment could be done as a...Ch. 12 - String Search Write a program that asks the user...Ch. 12 - Sentence Filter Write a program that asks the user...Ch. 12 - Array/File Functions Write a function named...Ch. 12 - File Encryption Filter File encryption is the...Ch. 12 - File Decryption Filter Write a program that...Ch. 12 - Prob. 11PCCh. 12 - Prob. 12PCCh. 12 - Inventory Program Write a program that uses a...Ch. 12 - Inventory Screen Report Write a program that reads...Ch. 12 - Average Number of Words If you have downloaded...Ch. 12 - Customer Accounts This program should be designed...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What are the advantages in implementing a language with a pure interpreter?
Concepts Of Programming Languages
Give an example of each of the following, other than those described in this chapter, and clearly explain why y...
Modern Database Management (12th Edition)
What is the difference between a void method and a value-returning method?
Starting out with Visual C# (4th Edition)
Convert each of the following mathematical formulas to a Java expression:
Absolute Java (6th Edition)
In an inheritance relationship, the _____ is the specialized class. a. superclass b. master class c. subclass d...
Starting Out with Programming Logic and Design (4th Edition)
A(n) ____ is a member of a class that holds data. a. method b. instance c. field d. constructor
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
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
- Question 1 of 1: Word Swap: Write a C++ program that will swap the words Caesar and Brutusin the file “source_file.txt”. You will need to load the file “source_file.txt” and finally write theupdated contents with the replaced words to the file “target_file.txt”.Successful operation should swap all occurrences of Caesar with Brutus and Brutus with Caesar.You can use functions from the cstring library. You are not allowed to use the string datatype. Once again, do not use string datatype.Please properly comment your code before submission.arrow_forwardWrite a void function that will merge the contents of two text files containing the chemical elements into a single binary file. The function's parameters will be three file pointers; each text file will contain an integer atomic number followed by the element name, chemical symbol and atomic weight. Here are two sample lines: 11 Sodium Na 22.9920 Calcium Ca 40.08 The function can assume that one file does not two copies of the same elements and that the binary output file should have the same property. IN C PLEASEarrow_forwardThis is my source code but why I cannot open the .txt file? #include <iostream>#include <conio.h>#include <stdlib.h>#include <fstream>using namespace std;//function declaration of calculateProfit and GreatestProfit (global)void calculateProfit(int *p, int M, int N, ofstream &fileout);int GreatestProfit(int *p, int M, int N, int *t, int *c); int main(){//Declare variablesint N, M, profit[50] = {0};int table = 0, chair = 0, highest_profit = 0;ofstream fileout;fileout.open("file.txt");if (fileout.fail()){cerr << "File cannot open" <<endl;exit(1) ;} //Read number of Type A and number of Type B input values form usercout << "The Number of Type A wood block is ";cin >> M;cout << "The Number of Type B wood block is ";cin >> N; //Displaying on consolecout << "-----------------------------------------" << endl;cout << "\tTables\tChair\tProfit" << endl;cout <<…arrow_forward
- . In c write a program that:a) takes an input file name from the command line;b) opens that file if possible;c) declares a C struct with three variables; these will have data types thatcorrespond to the data types read from the file (i.e. string, int, float);d) declares an array of C structs (i.e. the same struct type declared in point c);e) reads a record from the file and stores the values read into the appropriatestruct variable at the appropriate array index (for that record);f) continues reading each record into a struct (as in point 1e), and stores eachstruct containing the 3 values into the array of structs declared in point d;g) closes the file when all records have been read.Note that your program should print an error message in the event that the filecannot be opened successfully.arrow_forwardWrite a line-by-line explanation of the code: #include <unistd.h>#include <sys/stat.h>#include <sys/types.h>#include <stdio.h>#include <stdlib.h>#include <time.h>char * errormsg[] = {"\nUsage: ./12filestat <file|dir> [<file|dir>]\n\n", "\nFile does not exist !!\n\n", "\nError doing 'stat' on file\n\n"};void printerror(int msgnum, int exitcode, int exitflag);int main(int argc, char *argv[]){int i;mode_t fileperm;struct stat filedetails;char successmsg[] = "\nCommand executed successfully\n\n";if ( argc < 2 )printerror(0,2,1);for ( i = 1; i < argc; i++ ){printf("\n%s\n%s\n%s\n","----------------",argv[i],"----------------");if ( access(argv[i],F_OK) == -1 ){printerror(1,3,0);continue;}if ( lstat(argv[i],&filedetails) < 0 ){printerror(2,4,0);continue; }if ( S_ISREG(filedetails.st_mode) )printf("File type : Regular\n");else if ( S_ISDIR(filedetails.st_mode) )printf("File type : Directory\n");else if ( S_ISLNK(filedetails.st_mode)…arrow_forwardQuestion 1 of 1: Word Swap: Write a C++ program that will swap the words Caesar and Brutusin the file “source_file.txt”. You will need to load the file “source_file.txt” and finally write theupdated contents with the replaced words to the file “target_file.txt”.Successful operation should swap all occurrences of Caesar with Brutus and Brutus with Caesar.You can use functions from the cstring library. You are not allowed to use the string datatype.Please properly comment your code before submission.arrow_forward
- This class prints the first several lines of a file. The default is to print 5 lines, but the -n flag can specify a different number. If no file is specified on the command line, read from standard input. The code bekoow is to help get started. #include <stdio.h> #include <stdlib.h> // You may assume that lines are no longer than 1024 bytes #define LINELEN 1024 static void usage (void); int main (int argc, char *argv[]) { return EXIT_SUCCESS; } static void usage (void) { printf ("head, prints the first few lines of a file\n"); printf ("usage: head [FLAG] FILE\n"); printf ("FLAG can be:\n"); printf (" -n N show the first N lines (default 5)\n"); printf ("If no FILE specified, read from STDIN\n"); }arrow_forwardModify task4.c so it works like wc. Modify this program to count number of linesnumber of words, and number of characters (just like wc)from a file*/ #include <stdio.h>#include <unistd.h>#include <fcntl.h> int main(int argc, char *argv[]){ char *filename = argv[1]; int input = open(filename, O_RDONLY); char c; while(1){ int r = read(input,&c,1); if(r==0) break; write(1,&c, 1); } close(input); return 0;}arrow_forwardQ3:IN SML language how would I write a string to integer function that inputs a filename and returns zero if the contents inside the file is blank.arrow_forward
- Computer Science I need a C++ program that will take a list of random integers from a .txt file, scan them, and find + print the amount of prime numbers. I've seen this question posted here before but none of the responses have yielded the correct answer. The exact question is as follows: "Download the "Big List of Random Integers" file. Then write a program that makes use of the isPrime function you've already written that scans a file of integers and determines the number of primes found within. "arrow_forwardUsing these files BinaryFileRead.cpp // BinaryFileRead.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std; int main() { int *arrayToSort; char fileName[50]; int size,readVal; cout << "Enter a filename to sort => "; cin >> fileName; FILE *inFile; fopen_s(&inFile,fileName, "rb"); fread(&size, sizeof(size), 1, inFile); arrayToSort = new int[size]; for (int i = 0; i < size; i++) { fread(&readVal, sizeof(readVal), 1, inFile); arrayToSort[i] = readVal; } fclose(inFile); return 0; } Timing.cpp // Timing.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <time.h> //ctime #include <sys/timeb.h> //_timeb _ftime_s using namespace std; int main() { struct _timeb timebuffer; char timeline[26]; _ftime_s(&timebuffer); ctime_s(timeline,sizeof(timeline), &(timebuffer.time)); printf("The time is %.19s.%hu %s",…arrow_forwardChapter 4. PC #6. File Letter Counter (page 264) Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Class name: FileLetterCounter Hints: Hint 1. To read a single character from the keyboard, you need to read a full line and then take the first character in position 0. Hint 2. To count the occurrences of a given characters in a file you need to read the file line-by-line using a while loop, then for each line check all characters in all positions and increment the character counter for each occurrence. This will require to have a for-loop nested inside the while-loop. Here is a working code Please modify it so it passes the test cases because I run it it does not work: mport java.io.File;import java.io.FileNotFoundException;import java.util.Scanner;public class FileRead {public static void main(String[] args)…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
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