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...
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 <<...
**[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...
provide 3-4 paragraphs post (team 2) 1-What are 4 key things you learned about the topic...
provide 3-4 paragraphs post (team 2) 1-What are 4 key things you learned about the topic from reading their paper? 2-How does the topic relate to you and your current or past job? 3-Critique the paper in terms of the organization and quality.1- Employee Stress and how it has an Adverse Effect on a Company This paper explores employee stress and how it has an adverse effect on a company, its employees and the organization. Job stress can have a...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...