Hi, I've already learned C and Obj-C, but I'm taking a class in C++ in school right now. The instructor wants us to send him 3 things:
1.) The .cpp source code file.
2.) A screenshot of the output.
3.) The .out file.
#1 and 2 are easy enough to get, but I'm confused about #3. What is a .out file and how do I get one in Xcode 4?
Here's the code, I've highlighted the lines pertaining to making the file in blue.
1.) The .cpp source code file.
2.) A screenshot of the output.
3.) The .out file.
#1 and 2 are easy enough to get, but I'm confused about #3. What is a .out file and how do I get one in Xcode 4?
Here's the code, I've highlighted the lines pertaining to making the file in blue.
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
#define HEIGHT 7.0
int main()
{
[color=BLUE]ofstream outfile; //declare variable to write to file
outfile.open("hw1.out");[/color]
double side[2], area, volume;
side[0] = 2.0;
side[1] = 3.0;
area = side[0]*side[1]/2.0;
volume = area*HEIGHT/3.0;
cout<<"Side 1 is "<<side[0]<<"cm and side 2 is "<<side[1]<<"cm\n\n";
cout<<"First pyramid volume is "<<volume<<" cm^3\n\n";
[color=BLUE]outfile<<"Side 1 is "<<side[0]<<"cm and side 2 is "<<side[1]<<"cm\n\n";
outfile<<"First pyramid volume is "<<volume<<" cm^3\n\n";[/color]
cout<<"Enter new lengths for the two sides:\n";
cin>>side[0]>>side[1];
area = side[0]*side[1]/2.0;
volume = area*HEIGHT/3.0;
cout<<"Second pyramid volume is "<<volume<<" cm^3\n\n";
cout<<"Side 1 is "<<side[0]<<" cm and side 2 is "<<side[1]<<" cm\n\n";
cout<<"The volume of the pyramid to six decimals is:\n\n";
cout<<fixed<<setprecision(6)<<volume<<" cm^3\n\n";
[color=BLUE]outfile<<"Second pyramid volume is "<<volume<<" cm^3\n\n";
outfile<<"Side 1 is "<<side[0]<<"cm and side 2 is "<<side[1]<<"cm\n\n";
outfile<<"The volume of the pyramid to six decimals is:\n\n";
outfile<<fixed<<setprecision(6)<<volume<<" cm^3\n\n";
outfile.close();[/color]
return volume;
}
Last edited: