Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

T23-03-15752

QUESTION 1

(a)

#include <iostream>

using namespace std;

void muddy(int g, int h, int y) {

int result = g + h + y;

cout << "The sum of the three integers is: " << result << endl;

int main() {

muddy(1, 2, 3);

return 0;

(b)

#include <iostream>

#include <fstream>

using namespace std;

void abby(int g, int h, int y) {

int result = g + h + y;

ofstream outFile("my_file.txt");

if (outFile.is_open()) {

outFile << "The sum of the three integers is: " << result << endl;

outFile.close();
} else {

cout << "Unable to open file";

int main() {

abby(1, 2, 3);

return 0;

(c)

#include <iostream>

#include <fstream>

using namespace std;

void advancedSecondarySchoolAddition() {

ifstream inFile("my_file.txt");

ofstream outFile("my_file.txt", ios_base::app);

if (inFile.is_open() && outFile.is_open()) {

inFile >> g >> h >> y;

int result = g + h + y;

outFile << "The sum of the three integers is: " << result << endl;

inFile.close();

outFile.close();

} else {

cout << "Unable to open file";

}
}

int main() {

advancedSecondarySchoolAddition();

return 0;

(d)

Part (a)

#include <iostream>

using namespace std;

void muddy(float g, float h, int y) {

float result = g+h+y;

cout << "The sum of the two floats and one integer is: " << result << endl;

int main() {

muddy(1.5f, 2.5f, 3);

return 0;

Part (b)

#include <iostream>

#include <fstream>

using namespace std;

void abby(float g, float h, int y, const string &outputFile) {


float result = g + h + y;

ofstream outFile(outputFile);

if (outFile.is_open()) {

outFile << "The sum of the two floats and one integer is: " << result << endl;

outFile.close();

} else {

cout << "Unable to open file" << endl;

int main() {

abby(1.5f, 2.5f, 3, "output.txt");

return 0;

Part (c)

#include <iostream>

#include <fstream>

using namespace std;

void advancedSecondarySchoolAddition(const string &inputFile, const string &outputFile)


{

ifstream inFile(inputFile);

ofstream outFile(outputFile);

float g, h;

int y;

if (inFile.is_open() && outFile.is_open()) {

inFile >> g >> h >> y;


float result = g + h + y;

outFile << "The sum of the two floats and one integer is: " << result << endl;

inFile.close();

outFile.close();

} else {

cout << "Unable to open file" << endl;

int main() {

advancedSecondarySchoolAddition("input.txt", "output.txt");

return 0;

QUESTION 2

#include <iostream>

#include <fstream>

using namespace std;

void muddy(float g, float h, int y) {

float result = g + h + y;

cout << "The sum of the two floats and one integer is: " << result << endl;

void abby(float g, float h, int y) {

float result = g + h + y;

ofstream outFile("my_file.txt");

if (outFile.is_open()) {
outFile << "The sum of the two floats and one integer is: " << result << endl;

outFile.close();

} else {

cout << "Unable to open file";

void advancedSecondarySchoolAddition() {

ifstream inFile("my_file.txt");

ofstream outFile("my_file.txt", ios_base::app);

int y;

if (inFile.is_open() && outFile.is_open()) {

inFile >> g >> h >> y;

float result = g + h + y;

outFile << "The sum of the two floats and one integer is: " << result << endl;

inFile.close();

outFile.close();

} else {

cout << "Unable to open file";

int main() {

muddy(1.1f, 2.2f, 3);

abby(1.1f, 2.2f, 3);

advancedSecondarySchoolAddition();

return 0;

You might also like