bool compute(int one, int two, int & sum, int & product, int & quotient); sum wi
ID: 3646359 • Letter: B
Question
bool compute(int one, int two, int & sum, int & product, int & quotient); sum will be one + two, product will be one * two, andquotient will be one/ two provided that two is not 0. If the
quotient can be computed,( i.e. two is not 0 ) return true. If the quotient
cannot be computed,( i.e. two has a value of 0 ) return false. Write a
driver program to test both cases.
Explanation / Answer
#Include #include #include using namespace std; int Counter = 0; void LoadContents (const char*filename, string *array) { ifstream openfile (filename); if (openfile.is_open()) { while(!openfile.eof()) { openfile >> array[Counter]; Counter ++; } } } int main() { string Data[100]; // more than you need int numbers[6]; LoadContents("File_to_read.txt", Data); for (int i =0; i < 6; i ++) { numbers[i] = atoi(Data[i].c_str()); // this changes the first 6 things from your text file into numbers } // another thing you could do is check if it's a digit and if it's a digit then you make it into and // integer, this would be better because if numbers are scattered in the text file you'll be able to // identify where the numbers are. coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.