Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 13.3, Problem 13.19CP
What will be stored in the file out.dat after the following
#include <iostream>
#include <fstreara>
#include <iomanip>
using namespace std;
int main()
{
const int SIZE = 5;
ofstream outFile("out.dat");
double nums[ ] = {100.279, 1.719, 8.602, 7.777, 5.099};
outFile << setprecision(2);
for (int count = 0; count < SIZE; 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
do some changes in code and make it unique
#include <stdio.h>#include <stdlib.h>#include<string.h>//declaring functionsvoid firstFit(int [], int , int [],int );void bestFit(int [], int , int [],int );void worstFit(int [], int , int [],int );//starting programint main() {//declare partitions and processint partitions [] = {110, 450, 100, 250, 500};int processes [] = {212, 417, 112, 426};//getting their sizesint size_partitions = sizeof(partitions )/sizeof(partitions [0]);int size_processes = sizeof(processes )/sizeof(processes [0]);printf("Partitions size: ") ;for (int i=0; i<size_partitions; i++){printf("%d\t" ,partitions[i] );}//index partprintf("\nPartitions index: " );for (int i=0; i<size_partitions; i++){printf("%d\t" ,(i+1)) ;}printf( "\n" );// calling functionsfirstFit(partitions , size_partitions, processes , size_processes);bestFit(partitions , size_partitions, processes , size_processes);worstFit(partitions , size_partitions, processes ,…
The stream insertion operator << and the stream extraction operator >> are overloadedto handle all standard data types—including strings and memory addresses (stream insertion only)—and all user-defined data types T/F
In c++ you have a data in a text file, the data consists of a chatacter separated by a comma then an integer also separate md by a comma then another integer
Example
A,11,1
B,13,2
C,14,4
D,15,7
E,40,1
F,50,1
How will you read and store the data in a vector such that the character will be stored in vector char, and the two integers will be stored in vector x and y respectively.
Chapter 13 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 13.1 - Name three different C++ classes that can be used...Ch. 13.1 - Name three different C++ classes that can be used...Ch. 13.1 - What is the purpose of the second parameter to the...Ch. 13.1 - Why is it important for a program to close an open...Ch. 13.1 - Which file open flag causes all output to take...Ch. 13.1 - Which file open flag causes the contents of an...Ch. 13.1 - What happens if ios: :out is used by itself to...Ch. 13.1 - What happens if ios::out is used by itself to open...Ch. 13.1 - Write a sequence of C++ statements that reads in...Ch. 13.1 - Write a sequence of C++ statements that reads in...
Ch. 13.1 - Show how to use the constructor of the fstream...Ch. 13.1 - Consider two parallel arrays of the same size, one...Ch. 13.3 - Make the required changes to the following program...Ch. 13.3 - Describe the purpose of the eof member function.Ch. 13.3 - Assume the file input.txt contains the following...Ch. 13.3 - Describe the difference between reading a file...Ch. 13.3 - Describe the difference between the getline...Ch. 13.3 - Describe the purpose of the put member function.Ch. 13.3 - What will be stored in the file out.dat after the...Ch. 13.3 - The following program skeleton, when complete,...Ch. 13.5 - Write a short program that opens two files...Ch. 13.5 - How would the number 479 be stored in a text file?...Ch. 13.5 - Describe the differences between the write member...Ch. 13.5 - What arc the purposes of the two arguments needed...Ch. 13.5 - What are the purposes of the two arguments needed...Ch. 13.5 - Describe the relationship between fields and...Ch. 13.5 - Prob. 13.27CPCh. 13.7 - Describe the difference between the seekg and the...Ch. 13.7 - Describe the difference between the tellg and the...Ch. 13.7 - Describe the meaning of the following file access...Ch. 13.7 - What is the number of the first byte in a file?Ch. 13.7 - Briefly describe what each of the following...Ch. 13.7 - Describe the mode that each of the following...Ch. 13 - Prob. 1RQECh. 13 - Before a file can be used, it must first beCh. 13 - When a program is finished using a file, it shouldCh. 13 - The__________ header file is required for file I/O...Ch. 13 - Prob. 5RQECh. 13 - The_____________ file stream data type is for...Ch. 13 - The____________ file stream data type is for input...Ch. 13 - The ______ file stream data type is for output...Ch. 13 - Write a statement that defines a file stream...Ch. 13 - Write a statement that defines a file stream...Ch. 13 - Write a statement that defines a file stream...Ch. 13 - Write two statements that use the people file...Ch. 13 - Write two statements that use the pets file stream...Ch. 13 - Write two statements that use the places file...Ch. 13 - If a file fails to open, the file stream object...Ch. 13 - Write a program segment that defines a file stream...Ch. 13 - The same formatting techniques used with ______...Ch. 13 - The ______ member function reports when the end of...Ch. 13 - The ______ function reads a line of text from a...Ch. 13 - The _______ member function reads a single...Ch. 13 - The _____ member function writes a single...Ch. 13 - Prob. 22RQECh. 13 - Prob. 23RQECh. 13 - Prob. 24RQECh. 13 - In C++, _______ provide a convenient way to...Ch. 13 - The _______ member function writes raw binary data...Ch. 13 - The _______ member function reads raw binary data...Ch. 13 - The ______ operator is necessary if you pass...Ch. 13 - In _______ file access, the contents of the file...Ch. 13 - In _____ file access, the contents of a file may...Ch. 13 - The _______ member function moves a files read...Ch. 13 - The ______ member function moves a files write...Ch. 13 - The _______ member function returns a files...Ch. 13 - The _______ member function returns a files...Ch. 13 - The ______ mode flag causes an offset to be...Ch. 13 - The ______ mode flag causes an offset to be...Ch. 13 - The ______ mode flag causes an offset to he...Ch. 13 - A negative offset causes the files read or write...Ch. 13 - Give a pseudocode algorithm for determining the...Ch. 13 - Give a pseudocode algorithm for comparing two...Ch. 13 - Prob. 41RQECh. 13 - Suppose that you have two text files that contain...Ch. 13 - Each of the following programs or program segments...Ch. 13 - File Previewer Write a program that asks the user...Ch. 13 - File Display Program Write a program that asks the...Ch. 13 - Punch Line Write a program that reads and prints a...Ch. 13 - Tail of a File Write a program that asks the user...Ch. 13 - String Search Write a program that asks the user...Ch. 13 - Sentence Filter A program that processes an input...Ch. 13 - File Encryption Filter File encryption is the...Ch. 13 - File Decryption Filter Write a program that...Ch. 13 - Letter Frequencies The letter e is the most...Ch. 13 - Put It Back C++ input stream classes have two...Ch. 13 - Prob. 11PCCh. 13 - Insertion Sort on a File II Modify the program...Ch. 13 - Prob. 13PCCh. 13 - Prob. 14PCCh. 13 - Inventory Program Write a program that uses a...Ch. 13 - Inventory Program Write a program that uses a...Ch. 13 - Group Project 17. Customer Accounts This program...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Finish the program that takes a word as a command-line argument and looks up the word to see whether it is in t...
Programming in C
Suppose you write a program that is supposed to compute the day of the week (Sunday, Monday, and so forth) on w...
Java: An Introduction to Problem Solving and Programming (8th Edition)
Explain how each of the following types of integrity constraints is enforced in the SQL CREATE TABLE commands: ...
Modern Database Management (12th 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 denormalization?
Database Concepts (7th Edition)
Compile and run the sample code that uses show_bytes (file show-bytes. c) on different machines to which you ha...
Computer Systems: A Programmer's Perspective (3rd 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 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 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_forwardPROGRAM IN PLAIN C PLEASE! Write a void function that will merge the contents of two text files containing chemical elements sorted by atomic number and will produce a sorted file of binary records. The function’s parameters will be three file pointers. Each text file line 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.99 20 Calcium Ca 40.08 The function can assume that one file does not have two copies of the same element and that the binary output file should have this same property. Hint: When one of the input files is exhausted, do not forget to copy the remaining elements of the other input file to the result file.arrow_forward
- Modify the program 11-10 from pages 753-755 as follows: 1. To Length class files (Length.h and Length.cpp) add the operator overload for stream insertion (<<) and stream extraction (>>) from page 759. You should not use the modified version of class Length from page 759 because it contains more operator overloads. Instead of typing you can use copy/paste from Length1.h and Length1.cpp respectively. 2. In main() replace the lines 11-16 with appropriate usage of stream extraction overload (>>) to change "first" and "second" objects with values inputted by the end user. 3. In main(), replace the output on lines 21,22 and 25,26 with appropriate usage of stream insertion (<<) operator. The resulting output should be identical with the unmodified version of the program. 11-10: // This program demonstrates the Length class's overloaded // +, -, ==, and < operators. #include <iostream> #include "Length.h" using namespace std; int main() { Length first(0),…arrow_forwardIn c++ creates a function checkWord that:1) uses an input file stream to read input file (file1) containing correctwords from the English dictionary into a proper STL container.2) uses an input file stream to read another input file (file2) containinguntrusted English.3) Words that we need to check its correctness against the trusted filefrom the dictionary.4) Prints the incorrect words in file2 after checking it against file1.5) If there are no incorrect words, the function should print “All wordsare correct”.arrow_forwardWith the code below,dynamic memory allocation is not utilized at the main function. Rewrite the main function to incorporate dynamic allocation. #include<iostream>using namespace std;class Student{private:string studid, name; float marks[2], average;public:void setInput(){cout<<"Please enter student id :";getline(cin,studid);cout<<"Please enter name :";getline(cin,name);cout<<"\n\n";}void setMarks(){for(int i=0;i<2;i++){cout<<"Please enter mark for quiz "<<(i+1)<<" :";cin>>marks[i];calculate_average();} }void calculate_average(){float total;for(int i=0;i<2;i++){total += marks[i];}average = total / 2;}friend void display_info(Student);};void display_info(Student s){cout<<"\n\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;cout<<" Result Score "<<endl;cout<<"----------------------------"<<endl;cout<<"ID Name Average…arrow_forward
- Please write in C display Pages 10. Write function display Pages to do the following a. Return type void b. Parameter list includes i. Parameter that contains the page number, data type integer (i.e., page)ii. One-dimensional array, data type integer, that stores the page allocations (i.e., allocation) c. Display to the console the page number d. Write a looping construct to iterate through the frames (i.e.. FRAMES) i. Display to the console the memory block assigned based on the following logic 1. If the value stored at the current index of array allocation is -1 (ie., INVALID), output a dash (i.e., *-*) 2. Else, output the allocation at the current index of array allocationarrow_forwardComputer 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_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_forward
- C programming - (image attached ) Write a programme called pgmTile which takes 3 arguments, an input file (either ASCII or binary), an integer factor n, and an output file name template. It should divide the input file into nxn smaller images corresponding to parts of the image. For example, suppose that the invocation is: pgmTile sampleFile.pgm 3 sampleFile_<row>_<column>.pgm then the programme should read in sampleFile.pgm and output 9 smaller images, named: sampleFile_0_0.pgm sampleFile_0_1.pgm sampleFile_0_2.pgm sampleFile_1_0.pgm sampleFile_1_1.pgm sampleFile_1_2.pgm sampleFile_2_0.pgm sampleFile_2_1.pgm sampleFile_2_2.pgm i.e. substituting the relative position of the subimage in the larger image into the <row> and <column> tags in the template namearrow_forwardWrite C code which will read a line of characters (terminated by a \n) from input_file into a character array called buffer. NULL terminate the buffer upon reading a \n.arrow_forwardStarter Code #include <sys/types.h>#include <sys/wait.h>#include <unistd.h>#include <stdlib.h> #include <iostream> #include <pthread.h>#include <semaphore.h>#include <atomic> using namespace std; // The length of time the program should runint run_time; // The buffer that will be produced into and consumed from. int *buffer;int buffer_size; // The number of producers and consumers we will haveint num_producers;int num_consumers; // TODO: Declare the semaphores that you will need to implement this algorithm// Semaphores are of type sem_t // TODO: Declare a mutex that you will use in your implementation.// Use type pthread_mutex_t // TODO: Declare any other global variables you will need to // use to implement your algorithm // These atomic variables will be used simply to generate unique numbers// to identify each thread.atomic_int producer_num(0);atomic_int consumer_num(0); // This is the function that will be…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 Ptr
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