Exercise : An Overview of Computers and Programming Languages
1. Name two input devices.
2. Name two output devices.
3. What are the differences between machine languages and high-level languages?
4. Why do you need a compiler?
5. Why would you prefer to write a program in a high-level language rather than a
machine language?
6. What are the advantages of problem analysis and algorithm design over directly writing a
program in a high-level language?
7. Design an algorithm to find the average of four test scores.
12/18/2017
12/04/2017
BCS 1013 PSCP. Lab File Input and File Output
1. Consider the following C++ program. What is the content of "test.txt".
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
ofstream out("test.txt");
out << 10 << " " << 123.23 << "\n";
out << "This is a short text file.";
out.close();
system("PAUSE");
return EXIT_SUCCESS;
}
2. Write a program that prompts user to enter:-
Name
Age
State
Country
and write into a file named biodata.txt as follows.
Name : Ahmad Ashraaf
Age : 19
State : terengganu
Country: Malaysia
3. The following program is supposed to read two numbers from a file named input.dat and write the sum of the numbers to a file named output.dat. However, it fails to do so. Rewrite the program so that it accomplishes whatit is intended to do. (Also, include statements to close the files.)
#include
#include
using namespace std;
int main()
{
int num1, num2;
ifstream infile;
outfile.open("output.dat");
infile >> num1 >> num2;
outfile << "Sum = " << num1 + num2 << endl;
return 0;
}
4. Assume that each of the following statements applies to the same program.
i) Write a statement that opens file oldmast.dat for input; use an ifstream object called inOldMaster.
ii) Write a statement that opens file trans.dat for input; use an ifstream object called inTransaction.
iii) Write a statement that opens file newmast.dat for output , use ofstream object outNewMaster.
iv) Write a statement that reads a record from the file oldmast.dat. The record consists of integer accountNumber, string name and floating-point currentBalance; use ifstream object inOldMaster.
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
ofstream out("test.txt");
out << 10 << " " << 123.23 << "\n";
out << "This is a short text file.";
out.close();
system("PAUSE");
return EXIT_SUCCESS;
}
2. Write a program that prompts user to enter:-
Name
Age
State
Country
and write into a file named biodata.txt as follows.
Name : Ahmad Ashraaf
Age : 19
State : terengganu
Country: Malaysia
3. The following program is supposed to read two numbers from a file named input.dat and write the sum of the numbers to a file named output.dat. However, it fails to do so. Rewrite the program so that it accomplishes whatit is intended to do. (Also, include statements to close the files.)
#include
#include
using namespace std;
int main()
{
int num1, num2;
ifstream infile;
outfile.open("output.dat");
infile >> num1 >> num2;
outfile << "Sum = " << num1 + num2 << endl;
return 0;
}
4. Assume that each of the following statements applies to the same program.
i) Write a statement that opens file oldmast.dat for input; use an ifstream object called inOldMaster.
ii) Write a statement that opens file trans.dat for input; use an ifstream object called inTransaction.
iii) Write a statement that opens file newmast.dat for output , use ofstream object outNewMaster.
iv) Write a statement that reads a record from the file oldmast.dat. The record consists of integer accountNumber, string name and floating-point currentBalance; use ifstream object inOldMaster.
Subscribe to:
Posts (Atom)
Cara download Installer windows 10 dalam format ISO
1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan. ...
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdmA-K9pPPiDRT6Hxuu_F_tOPsmUxjJ6d5wBxej6IhcvufQGpHTbWHhmiuWoSt4Xt3gzS0WK38Cv_WmtaTEjs27BBs-SvSmTAJ439OsxbBg-ay0AlWzI0hxE2O_5aluh7uCs60wg3UkDU/s400/firefox-ctrl-shift-m-mode.jpg)
-
Latihan MS Word dengan elemen-elemen:- image, word art, table, shape dan word formatting (font,size,bold, italic,underline)
-
ANSWERS TO CHAPTER EXERCISES (CHAPTER 8) Review Questions 1. List and describe various types of output, including technolog...
-
Based on real life scenario on any local company/ organization which you are very familiar, define the problem that could be addressed thr...