Chapter 5 Quiz
.docx
keyboard_arrow_up
School
Kennesaw State University *
*We aren’t endorsed by this school
Course
2742
Subject
Computer Science
Date
Dec 6, 2023
Type
docx
Pages
1
Uploaded by kirahmartin
Chapter
5
Quizzes
Section
5.2
Quiz:
Redirect
Output
to
a
File
or
Program
Quiz:
Redirect
Output
to
a
File
or
Program
Choose
the
correct
answer
to
the
following
questions:
1.
Which
output
redirection
operator
displays
output
to
a
terminal
and
discards
all
error
messages?
A
&>
file
B
2>
&>
file
c
2>
/dev/null
D
1>
/dev/null
=
2.
Which
output
redirection
operator
utput
to
a
file
and
d
toadi
file?
A
>
file
2>
file2
B
>
file
1>
file2
C
>
file
&2>
file2
D
|
tee
file
Show
Solution
3.
Which
output
redirection
operator
sends
both
output
and
errors
to
a
file,
and
creates
it
or
overwrites
its
contents?
A
|
tee
file
B
28>
file
[
180>
file
D
&>
file
4.
Which
output
redirection
operator sends
output
and
errors
to
the
same
file
and
preserves
the
file
content
if
it
exists?
A
>
file
2>
file2
B
&>
file
C
|
>>
file
2>&1
D
>>
file
1>&1
5.
Which
output
redirection
operator
discards
all
messages
that
are
normally
sent
to
the
terminal?
A
>
file
2>
file2
B
&>
/dev/null
C
&>
/dev/null
2>
file
D
&>
file
o
[
o
6.
Which
output
redirection
operator
sends
output
to
both
the
screen
and
a
file
at
the
same
time?
A
&>
/dev/null
B
>
file
2>
file2
[
|
|
tee
file
D
|
<
file
Che«
7.
Which
output
redirection
operator
saves
output
to
a
file
and
discards
all
error
messages?
A
&>
file
B
|
tee
file
2>
/dev/null
[«
>
file
1>
/dev/null
>
file
2>
/dev/null
&=
=
o
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
*Code in Python
The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage>
Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period.
The report should be in tabular format with the appropriate header.
Each line should contain:
An employee’s name
The hours worked
The wages paid for that period.
An example of the program input and output is shown below:
Enter the file name: data.txt
Name Hours Total Pay
Lambert 34 357.00
Osborne 22 137.50
Giacome tti 5 503.50
arrow_forward
DCP 5101 PROGRAM DESIGN
QUESTION 2
Write a complete C program that creates a new file called audio.txt for both writing and reading.
The program prompts user to enter a series of inputs to calculate the audio size. User inputs and
audio size are then written into file audio.txt.
In main():
Open a new file called audio.txt for writing and reading.
If the file can't be opened, display error message "File could not be opened. Program
aborted." And quit the program.
Using a do-while loop:
o Prompt user to enter audio channel (either 1 for mono or 2 for stereo), sampling rate, time,
and bit depth.
o Calculate audio size.
●
●
●
O
O
====
From the beginning of file audio.txt, read and display all data from each audio record until the
end of file.
Close file audio.txt before program ends.
SAMPLE OUTPUT
2
1
■
Formula: audio channel x sampling rate x time x (bit depth / 8)
Write audio channel, sampling rate, time, bit depth and audio size into file audio.txt.
Prompt the user whether to continue…
arrow_forward
// Ex 7-1.cpp in this exercise you will use what you learned about opening a file and reading input //Read and follow the comments submit your code through the Exercise one quiz #include <fstream> #include <iostream> #include <string> using namespace std; int main() { //this is the code for exercise 7-1 ofstream data_in; //find and fix the error in this line data_in.open(myDVDFile.dat); //find and fix the error in this line string dvdName, dvdPrice, dvdShelf; data_in >> dvdShelf; data_in >> dvdPrice; data_in >> dvdName; /* use notepad to create a datafile named myDVDFile.dat that contains the following data Fargo 8.00 1A Amadaus 2.00 2C Casino 7.50 3B */ //add print statements to output dvdShelf, dvdPrice, dvdName record the values in your workbooks // there is a problem with the values fix it } // End of main function
arrow_forward
Problem set4.
arrow_forward
Use C++
Write a program that prints a menu of choices:
L -> Find the lowest value in a file
H -> Find the highest value in a file
A -> Find the average value in a file
Q -> Quit
Choose:
The program does input validation and asks the user to reenter as long as the user’s choice does not correspond to an item on the menu.
Invalid choice. Re-enter:
If the user selects any valid choice other than Quit, the program prompts the user to enter the file name,
Enter input file name:
then reads the content of the file and prints the value requested (highest value, lowest value or average value).
Highest value is 0
Lowest value is 0
Average value is 0
If the file cannot be opened or is empty, the program should display the message:
File empty or could not open file
Then the program displays the menu again. If the user selects Quit, the program prints “Exiting” and terminates.
Additional requirements – Make sure you meet all the requirements
You are not allowed to use arrays
You are…
arrow_forward
C programming
arrow_forward
You have the following function.
1 def funct(a):
file = open('file.txt')
3
while True:
line = file.readline()
if a in line:
4
print(line)
file.close()
7
The contents of the file named file.txt is as follows:
python
python is great!
python is the best
python is amazing!
What would the value of a be if the output is:
python is great!
python is amazing!
Answer:
arrow_forward
Program specifications:
Write a function called rCopy that copies the entire contents of one file to another, but copies them over in reverse order. This function should take the names of the input and output files as strings. If either file does not open for any reason, the function should output an error message stating the name of the file that didn’t open and then return the value false. Otherwise, if both files open correctly, the function should return true once the reverse copy has been completed.
For example, if a file named in.dat contains the following:
A c d 87arc 65879 9
then after the function call:
rCopy("in.dat", "out.dat")
the file out.dat should contain the following:
9 97856 cra78 d c A
You must solve this recursively!! To implement this recursively you will need to write a helper function that passes in an input and an output file stream. This helper function will be the recursive function. Recall that the expression cin.get(ch) will read in a single character from…
arrow_forward
Subject: Operating System
arrow_forward
HELP PLEASE: HOW DO I COMPLETE THIS IN C PROGRAM??????
This code will require some code modification. Those modifications include:
o Revise the code to read in a set of 20,000 words from a file
o Revise the code to accept from the keyboard a word to lookup and report either that the word is in the Trie or the word is not in the Trie
Run the program 5 times and take a screen shot showing the output of the run with two of the words not in the Trie and three words located in the Trie.
Given Code:
#include <stdio.h>#include <stdlib.h>
// Define the character size#define CHAR_SIZE 26
// Data structure to store a Trie nodestruct Trie {struct Trie* character[CHAR_SIZE];int isLeaf; // 1 when the node is a leaf node};
// Function that returns a new Trie nodestruct Trie* getNewTrieNode() {int i;struct Trie* node = (struct Trie*)malloc(sizeof(struct Trie));node->isLeaf = 0;
for (i = 0; i < CHAR_SIZE; i++) {node->character[i] = NULL;}
return node;}
// Iterative function to…
arrow_forward
3/3
100%
Exercise 5:
Write a C++ program which reads from a file inventory records of some items ("inventory.txt"), item and
the price and the count of that item. The program calculates the total cost per item and the overall cost
and the output should be saved in a file called("report.txt") as shown below.
inventroy.bxt- Notepad
Eile Edit Format View Help
1.5 1200
101
112 2.8 400
033 5.00 700
604 1,00 1900
Item
Price
Total co3
1.500
2.800
5.00
"1.000
1120.000
3500.000
1900.000
112
604
The overli ceat H 320.000
arrow_forward
flowchrt for the code below
//C++ Code
#include<iostream>#include<fstream>using namespace std;/*Create a global variable of type ofstream for the output file*/ofstream outfile; /** This function asks the user for the number of employees in the company. This value should be returned as an int. The function accepts no arguments (No parameter/input).*/int NumOfEmployees();/** accepts an argument of type int for the number of employees in the company and returns the total of missed days as an int. This function should do the following:Asks the user to enter the following information for each employee:The employee number (ID) (Assume the employee number is 4 digits or fewer, but don't validate it).The number of days that employee missed during the past year.Writes each employee number (ID) and the number of days missed to the output file */int TotDaysAbsent(int numberOfEmployees);/* calculates the average number of days absent.The function takes two arguments:the number of…
arrow_forward
Code in python
arrow_forward
Programming Exercises
As mentioned before, you will be answering all the following questions in one single python file
and the person running your file will be prompted to choose which one of these programming
exercises they wish to run.
A good approach to design this file is to have a main function for each of the questions (main1,
main2, etc.). These functions will be called when the user chooses each of the questions (if the
user chooses 1, mainl will be executed and so on). You can call different functions in each of your
mains if you wish.
Below are the programming exercises. The questions are in all levels, some of them are very easy,
and some are more challenging. Start with the questions that are easier for you and then try to
answer as many questions as possible. For grading, we will be looking at the codes, so even if you
have not completely answered a question, make sure you still include your code in the submitted
file as you may receive a partial grade for it.
Note: all…
arrow_forward
It is due in C ++
Please if you can make I instruction for each file.
A sample run is as follows:
Enter the company name: TC Energy
Enter TC Energy's stock symbol: TRP.TO
Enter TC Energy's current stock price: 55
Enter TC Energy's annual dividend per share: 3.24
Enter the company name: Canadian Utilities
Enter Canadian Utilities's stock symbol: CU.TO
Enter Canadian Utilities's current stock price: 31.70
Enter Canadian Utilities's annual dividend per share: 1.76
Enter the company name: Bank of Nova Scotia
Enter Bank of Nova Scotia's stock symbol: BNS.TO
Enter Bank of Nova Scotia's current stock price: 70.08
Enter Bank of Nova Scotia's annual dividend per share: 3.60
Enter the company name: TransAlta Renewables
Enter TransAlta Renewables's stock symbol: RNW.TO
Enter TransAlta Renewables's current stock price: 21.75
Enter TransAlta Renewables's annual dividend per share: 0.94
Enter the company name: Toronto Dominion Bank
Enter Toronto…
arrow_forward
2. Task 1: Opening a File
Write C statements which tests to see if file has opened the data file successfully. If not, print an error message and exit the program.
NOTE:Your source code must display any of the given sample output below.It means your source code should be flexible enough to meet any of the given sample output.Your source code output must be identical to any of the given sample output.It means you have to strictly follow what are the displayed text, labels, casing of characters in the sample output.Strictly follow the naming of file.
Sample OUTPUT1:
Enter File Name: file1.txt
The file can’t be open. File does not exists.
Sample OUTPUT2:
Enter File Name: file2.txt
The file has been opened successfully.
arrow_forward
2. Task 1: Opening a File
Write C statements which tests to see if file
has opened the data file successfully. If not,
print an error message and exit the
program.
NOTE:
Your source code must display any of the given sample output below.
It means your source code should be flexible enough to meet any of the given
sample output.
Your source code output must be identical to any of the given sample output.
It means you have to strictly follow what are the displayed text, labels, casing
of characters in the sample output.
Strictly follow the naming of file.
arrow_forward
C++
arrow_forward
Given a file of text, output the number of Vowels, Consonants, Digits and Special characters in each line of the file.
Definitions:
A consonant is any alphabetic character that's not a vowel
A special character is any character that is neither alphabetic nor a digit.
Ex: If the input file is:
●
data2.txt
the output is:
Character analysis of each line from file data2.txt
Line
Why did the duck cross the road?
To prove he wasn't chicken!
Why did the cow cross the road?
●
Character Count.
V: 7
V: 7
V: 7
V: 8
/**
C: 18
D: 0
C: 14 D: 0
To get to the udder side!
Note: All input files on which your program will be tested can be downloaded below.
Step 0: Work on this project using Clion.
@param
@param
@param
C: 17 D: 0
Step 2: Create a function following the specification:
C: 11
S: 7
D: 0
S: 6
• The first step is to create a new project (we will call it lab04). Follow these instructions.
O Click New Project on the Welcome screen or select File | New Project from the main menu.
O
In the New…
arrow_forward
It is necessary to define the functions that are part of the I stream.
arrow_forward
In C Language
arrow_forward
Language: Python
1. The sample input will have to be in Text File (.TXT)
2. By using the first function, this program reads score and name values from a file. The program then determines the grade for each students by using the second function. Finally, the program displays the name, score, and grade information on the console. The two functions are shown in the images attached below:
arrow_forward
Q2: Write a complete C++ program that reads the contents of the text file "mydata.txt", character by character. And appends them to the end of text file "myoutput.txt" . The main function calculates and prints the number of characters read and copied between the files.
arrow_forward
I need this Code By C++
Please stick to the code at the bottom of the page
Just By C++
arrow_forward
Directions:
Typing make at the command line should create executable named bitflip.
Only bitflip.c and Makefile are included in the input unless permission is given for any other files.
Program should have consistent indentation.
Code should be readable with good variable and function names.
No use of "break or continue statements" except in a switch.
Program must exit with a return code of 0 on success and an error code in other cases.
The program used getopt to parse the command line.
Whenever an error occurs on the command line the user is given the usage statement and an appropriate error message if needed.
If the -o option is used the output will go to a file named as specified without changing the filename at all otherwise it will go to stdout.
-e option works as specified using bitwise operations.
-f option works as specified using bitwise operations.
-a option works as specified using bitwise operations.
-s option works as specified using bitwise operations.
Program outputs…
arrow_forward
Directions:
Typing make at the command line should create executable named bitflip.
Only bitflip.c and Makefile are included in the input unless permission is given for any other files.
Program should have consistent indentation.
Code should be readable with good variable and function names.
No use of "break or continue statements" except in a switch.
Program must exit with a return code of 0 on success and an error code in other cases.
The program used getopt to parse the command line.
Whenever an error occurs on the command line the user is given the usage statement and an appropriate error message if needed.
If the -o option is used the output will go to a file named as specified without changing the filename at all otherwise it will go to stdout.
-e option works as specified using bitwise operations.
-f option works as specified using bitwise operations.
-a option works as specified using bitwise operations.
-s option works as specified using bitwise operations.
Program outputs…
arrow_forward
1 Write a program that writes a series of random
numbers to a file. Each random number should
be in the range 1 through 500. The application
should let the user user specify how many ran-
dom numbers the file will hold. Use an excep-
tion to make sure that an integer was typed in
by the user for the #to generate. If not re
ask the user for input in the except clause
until they input the correct number. You
should do this in one function named main
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Related Questions
- *Code in Python The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage> Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report should be in tabular format with the appropriate header. Each line should contain: An employee’s name The hours worked The wages paid for that period. An example of the program input and output is shown below: Enter the file name: data.txt Name Hours Total Pay Lambert 34 357.00 Osborne 22 137.50 Giacome tti 5 503.50arrow_forwardDCP 5101 PROGRAM DESIGN QUESTION 2 Write a complete C program that creates a new file called audio.txt for both writing and reading. The program prompts user to enter a series of inputs to calculate the audio size. User inputs and audio size are then written into file audio.txt. In main(): Open a new file called audio.txt for writing and reading. If the file can't be opened, display error message "File could not be opened. Program aborted." And quit the program. Using a do-while loop: o Prompt user to enter audio channel (either 1 for mono or 2 for stereo), sampling rate, time, and bit depth. o Calculate audio size. ● ● ● O O ==== From the beginning of file audio.txt, read and display all data from each audio record until the end of file. Close file audio.txt before program ends. SAMPLE OUTPUT 2 1 ■ Formula: audio channel x sampling rate x time x (bit depth / 8) Write audio channel, sampling rate, time, bit depth and audio size into file audio.txt. Prompt the user whether to continue…arrow_forward// Ex 7-1.cpp in this exercise you will use what you learned about opening a file and reading input //Read and follow the comments submit your code through the Exercise one quiz #include <fstream> #include <iostream> #include <string> using namespace std; int main() { //this is the code for exercise 7-1 ofstream data_in; //find and fix the error in this line data_in.open(myDVDFile.dat); //find and fix the error in this line string dvdName, dvdPrice, dvdShelf; data_in >> dvdShelf; data_in >> dvdPrice; data_in >> dvdName; /* use notepad to create a datafile named myDVDFile.dat that contains the following data Fargo 8.00 1A Amadaus 2.00 2C Casino 7.50 3B */ //add print statements to output dvdShelf, dvdPrice, dvdName record the values in your workbooks // there is a problem with the values fix it } // End of main functionarrow_forward
- Problem set4.arrow_forwardUse C++ Write a program that prints a menu of choices: L -> Find the lowest value in a file H -> Find the highest value in a file A -> Find the average value in a file Q -> Quit Choose: The program does input validation and asks the user to reenter as long as the user’s choice does not correspond to an item on the menu. Invalid choice. Re-enter: If the user selects any valid choice other than Quit, the program prompts the user to enter the file name, Enter input file name: then reads the content of the file and prints the value requested (highest value, lowest value or average value). Highest value is 0 Lowest value is 0 Average value is 0 If the file cannot be opened or is empty, the program should display the message: File empty or could not open file Then the program displays the menu again. If the user selects Quit, the program prints “Exiting” and terminates. Additional requirements – Make sure you meet all the requirements You are not allowed to use arrays You are…arrow_forwardC programmingarrow_forward
- You have the following function. 1 def funct(a): file = open('file.txt') 3 while True: line = file.readline() if a in line: 4 print(line) file.close() 7 The contents of the file named file.txt is as follows: python python is great! python is the best python is amazing! What would the value of a be if the output is: python is great! python is amazing! Answer:arrow_forwardProgram specifications: Write a function called rCopy that copies the entire contents of one file to another, but copies them over in reverse order. This function should take the names of the input and output files as strings. If either file does not open for any reason, the function should output an error message stating the name of the file that didn’t open and then return the value false. Otherwise, if both files open correctly, the function should return true once the reverse copy has been completed. For example, if a file named in.dat contains the following: A c d 87arc 65879 9 then after the function call: rCopy("in.dat", "out.dat") the file out.dat should contain the following: 9 97856 cra78 d c A You must solve this recursively!! To implement this recursively you will need to write a helper function that passes in an input and an output file stream. This helper function will be the recursive function. Recall that the expression cin.get(ch) will read in a single character from…arrow_forwardSubject: Operating Systemarrow_forward
- HELP PLEASE: HOW DO I COMPLETE THIS IN C PROGRAM?????? This code will require some code modification. Those modifications include: o Revise the code to read in a set of 20,000 words from a file o Revise the code to accept from the keyboard a word to lookup and report either that the word is in the Trie or the word is not in the Trie Run the program 5 times and take a screen shot showing the output of the run with two of the words not in the Trie and three words located in the Trie. Given Code: #include <stdio.h>#include <stdlib.h> // Define the character size#define CHAR_SIZE 26 // Data structure to store a Trie nodestruct Trie {struct Trie* character[CHAR_SIZE];int isLeaf; // 1 when the node is a leaf node}; // Function that returns a new Trie nodestruct Trie* getNewTrieNode() {int i;struct Trie* node = (struct Trie*)malloc(sizeof(struct Trie));node->isLeaf = 0; for (i = 0; i < CHAR_SIZE; i++) {node->character[i] = NULL;} return node;} // Iterative function to…arrow_forward3/3 100% Exercise 5: Write a C++ program which reads from a file inventory records of some items ("inventory.txt"), item and the price and the count of that item. The program calculates the total cost per item and the overall cost and the output should be saved in a file called("report.txt") as shown below. inventroy.bxt- Notepad Eile Edit Format View Help 1.5 1200 101 112 2.8 400 033 5.00 700 604 1,00 1900 Item Price Total co3 1.500 2.800 5.00 "1.000 1120.000 3500.000 1900.000 112 604 The overli ceat H 320.000arrow_forwardflowchrt for the code below //C++ Code #include<iostream>#include<fstream>using namespace std;/*Create a global variable of type ofstream for the output file*/ofstream outfile; /** This function asks the user for the number of employees in the company. This value should be returned as an int. The function accepts no arguments (No parameter/input).*/int NumOfEmployees();/** accepts an argument of type int for the number of employees in the company and returns the total of missed days as an int. This function should do the following:Asks the user to enter the following information for each employee:The employee number (ID) (Assume the employee number is 4 digits or fewer, but don't validate it).The number of days that employee missed during the past year.Writes each employee number (ID) and the number of days missed to the output file */int TotDaysAbsent(int numberOfEmployees);/* calculates the average number of days absent.The function takes two arguments:the number of…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