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
Concept explainers
Question
Chapter 13.5, Problem 13.27CP
Program Plan Intro
The “write” member function:
The “write” member function is one of the file stream object’s functions and it is used to write the binary data or raw data in the specified file.
The syntax of the “write” function is as follows:
filestreamobject.write(address,size)
- The “filestreamobject” is the object name of a stream.
- The argument “address” indicates the part of the memory that is to be written on the specified file. This argument must be address or pointer of a char.
- The argument “size” indicates the number of bytes which is to be written. This argument must be an integer.
Typecast – Converts the value of one type into another type.
The type cast which is used to convert the pointer of one type to another type is “reinterpret_cast”.
- The basic format for “reinterpret_cast” as follow as:
- reinterpret_cast <dataType>( argument)
- Here, the “dataType” is the type that user converting to, similarly the “argument” is the value which the user wants to convert.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Rectangle's Length and Width
Code in C language
// WARNING: Do not add, remove, or change anything before the line 19 of this file.// Doing so will nullify your score for the activity.
#include <stdio.h>#include "rectangle.h"
int get_length(Rectangle *rect);int get_width(Rectangle *rect);
int main() { int ur_x, ur_y, ll_x, ll_y; printf("UR's X: "); scanf("%d", &ur_x); printf("UR's Y: "); scanf("%d", &ur_y); printf("LL's X: "); scanf("%d", &ll_x); printf("LL's Y: "); scanf("%d", &ll_y); // TODO: Initialize the points here // Point ... // TODO: Initialize the rectangle here // Rectangle ... // TODO: Call the get_length here int len = ___; printf("\nLength: %d", len); // TODO: Call the get_width here int wid = ___; printf("\nWidth: %d", wid); return 0;}
// TODO implement get_lengthint get_length(Rectangle *rect) { return 0;}
// TODO implement get_widthint get_width(Rectangle *rect){ return 0;}
refer to pics for instructions
Language: C++
Subject: OOP
Task:You have to write a program to store information of university students. There can be many students in university, so you can make a Student class and objects of class Student to store information. The university is interested in storing information about student’s name, enrollment, department, class, CGPA and gender. You can store this information as data member values for each object. But as you already know you cannot directly access data members of a class, so you need to make member functions to access data members. You can make as many member functions as you want. There are no restrictions.
The University is interested in knowing the student’sname with highest CGPA in a specific class. For example if you entered information of 10 students from class BSIT 2 and information of 5 students from class BSIT 3, and it is asked to find name of student with highest CGPA in BSIT 2 then your program must be able to find details of highest CGPA student from…
First programming homework
Create a class of records for a gradebook called Rec.
The data should be private, and should include a firstname, lastname, array of three grades, and a field for average grade.
Build two constructors: a default constructor and a constructor that takes the first and last name.
Build a function to read the data, either from a file or from cin. The read function reads the two names and three grades, but does not read the average grade.
Build a write function that writes the data either to a file or to cout. The write function prints all of the data on one line with spaces between fields.
Build a function to calculate the average grade field.
Build an overloaded operator == to compare two records. This should be implemented as a friend function.
Declare the constructors and functions in the body of the class, but implement them outside the class.
I will provide you with a driver called hw1.cpp in ~cthorpe/public/142 and with a test file HW1.txt in the same…
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...
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
- (Data processing) A bank’s customer records are to be stored in a file and read into a set of arrays so that a customer’s record can be accessed randomly by account number. Create the file by entering five customer records, with each record consisting of an integer account number (starting with account number 1000), a first name (maximum of 10 characters), a last name (maximum of 15 characters), and a double-precision number for the account balance. After the file is created, write a C++ program that requests a user-input account number and displays the corresponding name and account balance from the file.arrow_forwardPlease create separate filesarrow_forwardAdd distribution function in code The system should allow the employees to list all distributed vaccines and their accumulated quantities read from the dist. txt file. Note: The vaccines and their distributed quantities need to be sorted in descending order (with highest quantity listed first followed by second highest and so on) using Bubble sort before displaying on the screen. MY C Programming CODE: #include <stdio.h> #include <stdlib.h> #include <string.h> // Function Declarations void create_inventory(); void update_vacc_qty(); int search_vaccine(); void display_vaccine(); // Main Function starts here int main() { create_inventory(); display_vaccine(); search_vaccine(); //update_vacc_qty(); return 0; } //Function to Create Vaccine.txt as per the given table void create_inventory() { int option = 1; // variables to collect data as per table given char vaccName[15]; char vaccCode[2]; char country[15]; int qty; float populaion; //File definition FILE *infile;…arrow_forward
- The stream member function good returns true if the bad, fail and eof member functions all return false. T/Farrow_forwardASSIGNMENT: Student Data Write a program that uses two structures Name and Student to store the following information for multiple students: 1. Create a NAME structure that consists of • First Name, • Middle Initial, and • Last Name. 2. Create a STUDENT structure that contains student information (Include the NAME structure within the Student information structure) o Name o ID o email • SSN • Program (an enum type containing programs such as CSCI, DBMS, INFM, SDEV)arrow_forwardIf a nonrecoverable error occurs during a stream operation, the bad member functionwill return true. T/Farrow_forward
- SUBJECT: OOPPROGRAMMING LANGUAGE: C++ In main program, ask user for the number of students whose records must be inserted in file. Afterwards, take records from user, calculate grade of students and store all records in a file. Code: #include <iostream> #include <conio.h> using namespace std; #define MAX 10 class student { private: char name[30]; char sec[30]; char sem[30]; int course1M, course2M, course3M; int EnrollNo; int total; float avg; char Grade; public: student() { EnrollNo = 0; course1M = 0; course2M = 0; course3M = 0; total = 0; avg = 0; } void SetDetails(); void GetDetails(); float grade(float avg); }; void student::SetDetails() {…arrow_forwardYou can dereference a smart pointer with the * operator. True Falsearrow_forwardC++ Code Dynamic Arraysarrow_forward
- C sharparrow_forwardstruct employee{int ID;char name[30];int age;float salary;}; (A) Using the given structure, Help me with a C program that asks for ten employees’ name, ID, age and salary from the user. Then, it writes the data in a file named out.txt (B) For the same structure, read the contents of the file out.txt and print the name of the highest salaried employee and youngest employee names name in the outputscreen.arrow_forward7. Employee Management System This exercise assumes you have created the Employee class for Programming Exercise 4. Create a program that stores Employee objects in a dictionary. Use the employee ID number as the key. The program should present a menu that lets the user perform the following actions: Look up an employee in the dictionary Add a new employee to the dictionary Change an existing employee’s name, department, and job title in the dictionary Delete an employee from the dictionary Quit the program When the program ends, it should pickle the dictionary and save it to a file. Each time the program starts, it should try to load the pickled dictionary from the file. If the file does not exist, the program should start with an empty dictionary.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:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
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++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning