Answer the following: (a)Which program-defined functions is mixing double and in
ID: 3889467 • Letter: A
Question
Answer the following:
(a)Which program-defined functions is mixing double and int in its calculations and should be using "type casting"?
(b)Which lines of code declare local variables that are object references?
(c)As written, why won't the function setOutputFormat() compile?
(d)Could we change the call to the formatData() function at line 44 to direct the output to the terminal instead of an open file (ie. use cout as the second argument)? Why or why not?
(e)In calculateStudentAverage() we set the variable totalScore to an initial value (line 92) but do not initialize the variable score (line 94)? Is this an error? Why or why not.
(f)Which function parameter is also being used as an argument?
(g)The calculateStudentAverage() function has one or more logical errors: find one of those errors and describe it.
(h)Could we change the call to the formatData() function at line 44 to direct the output to the terminal instead of an open file (ie. use cout as the second argument)? Why or why not?
Explanation / Answer
Hi Let me know if you need more information:-
=======================================
(a)Which program-defined functions is mixing double and int in its calculations and should be using "type casting"?
calculateStudentAverage --> is mixing double and int in its calculations we can use typecasting based on what type of values you want.
courseAvg = totalScore / numberOfStudents; -> Integer value come as output (double)numberOfStudents
===============
(b)Which lines of code declare local variables that are object references?
The below code declare local variables that are object references:-
-------------------------
void setOutputFormat(ostream out, int decimal_places) {
void formatData(istream& in, ostream& out, int decimalPlaces, double avg) {
int calculateStudentAverage(ifstream& inp, double& courseAvg) {
===========================
(c)As written, why won't the function setOutputFormat() compile?
Gives compilation error.
ios_base.h: In copy constructor 'std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)':
ios_base.h:855:5: error: 'std::ios_base::ios_base(const std::ios_base&)' is private
basic_ios.h:67:11: error: within this context
==================
(d)Could we change the call to the formatData() function at line 44 to direct the output to the terminal instead of an open file (ie. use cout as the second argument)? Why or why not?
Yes we can change call to the formatData() function at line 44 to direct the output to the terminal instead of an open file
===
out << "Average is: " << avg << endl; will print on to the terminal.
extern ostream cout; this will be defined in #include <iostream>
==============
(e)In calculateStudentAverage() we set the variable totalScore to an initial value (line 92) but do not initialize the variable score (line 94)? Is this an error? Why or why not.
No we do not get any error that is local to the function.
(f)Which function parameter is also being used as an argument?
void formatData(i.....
========
(g)The calculateStudentAverage() function has one or more logical errors: find one of those errors and describe it.
Depends how the input file is mentioned if one value mentioned in file belongs to one persion then it will be calculating the proper manner.if not then we need to implement in other way.
do {
inp >> score;
totalScore = totalScore + score;
numberOfStudents++;
// inp >> score;this line must be commented in order to read all the values from file and to get proper values. if you mention this in code first time [inp >> score;] takes the value and calcultes the score and for second time it is not.it will skip that value.
}
===========
h)Could we change the call to the formatData() function at line 44 to direct the output to the terminal instead of an open file (ie. use cout as the second argument)? Why or why not?
Yes we can change call to the formatData() function at line 44 to direct the output to the terminal instead of an open file
===
out << "Average is: " << avg << endl; will print on to the terminal.
extern ostream cout; this will be defined in #include <iostream>
========
================
Thanks
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.