Question

1.What is the difference between class/object? 2.Did you think about classes/objects around you since the last...

1.What is the difference between class/object?

2.Did you think about classes/objects around you since the last session?

3.What library do we need for processing file I/O?

4.What is the class for the input file stream? Give an example

5.What is the class for the output file stream? Give an example

6.Why do you want to use files instead of using input?

7.How do you read from a file? give an example

8.How do you write to a file? give an example

9.What is a member function?

10.How do you catch error in reading /writing files?

11.What happens if you try to open a file for writing which does not exist?

12.How do you append to the end of the file instead of losing your old data?

Hi there, answer the following questions using knowledge from C++

Thank You,

Vincent

Homework Answers

Answer #1

1.What is the difference between class/object?

Class : A class is a template for creating objects in program, it a logical entity and no memory is allocated when class is created and declared only once.

Object :  The object is an instance of a class, it a physical entity, allocates memory space whenever, can be created multiple times.

Example: Car.   Example: Jaguar, BMW, Tesla, etc.

3.What library do we need for processing file I/O?

The ANSI C standard provides IO functions into (stdio.h).
C++ continues this and it also IO in libraries iostream and fstream.

4.What is the class for the input file stream? Give an example

The istream class
It provides formatted input and unformatted input.

// for scanning a single char 
    cin.get(ch); 
    cout << ch; 

5.What is the class for the output file stream? Give an example

The ostream Class :
It provides two output functions: formatted output and unformatted output.

// single char onto the screen. 
    cout.put(ch); 

7.How do you read from a file? give an example

Information from a file is read using the stream extraction operator (>>).
The only difference is that you use an ifstream or fstream object instead of the cin object.

// write inputted data into the file.
outfile << data << endl;

8.How do you write to a file? give an example

Information to a file from your program using the stream insertion operator (<<). 
The only difference is that you use an ofstream or fstream object instead of the cout object.

// write inputted data into the file.
   outfile << data << endl;

9.What is a member function?

Member functions are the functions, which have their declaration inside the class definition and works on the data members of the class.
infile >> data; 
 cout << data << endl;

11.What happens if you try to open a file for writing which does not exist?

Opening a file for reading fails if the file does not exist.
If file_name does not exists, no exception is thrown. We need to handle the case to throw exception.
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Goal:   Manage the inventory of objects sold in an online or brick and mortar store. If...
Goal:   Manage the inventory of objects sold in an online or brick and mortar store. If you can't implement all of the features of Project described in this document, implement what you can. Start by implementing the StockItem class, and its derived classes. Then add in the InventoryManager class later. In each case, the test files must be in separate classes. UML Diagram: Use Violet or other drawing software to draw the UML diagrams of each class that you use...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I feel like I know how to write that. What I'm having trouble with is implementing two files the professer gave us. I would appreicate any help in understanding their purpose as in if Im supposed to take information from those files or give it information. Thank you! I have attatched the homework instructions and the two files given. Implementation The main program, called calculator.cpp...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
I did already posted this question before, I did get the answer but i am not...
I did already posted this question before, I did get the answer but i am not satisfied with the answer i did the code as a solution not the description as my solution, so i am reposting this question again. Please send me the code as my solution not the description In this project, build a simple Unix shell. The shell is the heart of the command-line interface, and thus is central to the Unix/C programming environment. Mastering use of...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you start doing anything… This project involves implementing a simple university personnel management program. The program contains two different kinds of objects: students and faculty. For each object, the program stores relevant information such as university ID, name, etc. Different information is stored depending on the type of the object. For example, a student has a GPA, while a faculty has a title and department...
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question....
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question. Thank you! Here’s the contents of a file called example.cpp: // example.cpp #include "LinkedList.h" #include <iostream> #include <string> using namespace std; int main() { cout << "Please enter some words (ctrl-d to stop):\n"; LinkedList lst; int count = 0; string s; while (cin >> s) { count++; lst.add(remove_non_letters(s)); } // while cout << "\n" << count << " total words read in\n"; cout <<...
Do the TODOs in SongFileAccessor.java. It inherits from FileAccessor class. TODO 1: Implement the processLine method....
Do the TODOs in SongFileAccessor.java. It inherits from FileAccessor class. TODO 1: Implement the processLine method. When the text file is processed, each line of text will be passed to processLine . Each line contains 4 fields: title, album, artist, and play time. The album field is optional. Each field is separated by a comma. TODO 2: Implement the songToCSVString method. This method takes a Song object as a parameter and returns a String which is the csv representation of...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these classes: Product, Customer, and Store. All data members of each class should be marked as **private** (a leading underscore in the name). Since they're private, if you need to access them from outside the class, you should do so via get or set methods. Any get or set methods should be named per the usual convention ("get_" or "set_" followed by the name of...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called keys with other objects called values. It is implemented as a Java class that uses arrays internally. 1. Theory. A map is a set of key-value pairs. Each key is said to be associated with its corresponding value, so there is at most one pair in the set with a given key. You can perform the following operations on maps. You can test if...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class Zillion implements a decimal counter that allows numbers with an effectively infinite number of digits. Of course the number of digits isn’t really infinite, since it is bounded by the amount of memory in your computer, but it can be very large. 1. Examples. Here are some examples of how your class Zillion must work. I’ll first create an instance of Zillion. The string...