Computer Science, asked by hamzakhan34866, 10 months ago

Write a program in C++ that will create two text files containing some integer numbers (7)
separated with blank spaces. The program will read the numbers from both the text files
and will perform sum and product operations on these numbers. The results of these
operations will be written to the third text file.

Answers

Answered by nksinha36
0

Let us begin by writing our first C++ program that prints the message "hello, world" on the display console.

Step 1: Write the Source Code: Enter the following source codes using a programming text editor (such as NotePad++ for Windows or gedit for UNIX/Linux/Mac) or an Interactive Development Environment (IDE) (such as CodeBlocks, Eclipse, NetBeans or Visual Studio - Read the respective "How-To" article on how to install and get started with these IDEs).

Do not enter the line numbers (on the left panel), which were added to help in the explanation. Save the source file as "hello.cpp". A C++ source file should be saved with a file extension of ".cpp". You should choose a filename which reflects the purpose of the program.

1

2

3

4

5

6

7

8

9

10

/*

* First C++ program that says hello (hello.cpp)

*/

#include <iostream> // Needed to perform IO operations

using namespace std;

int main() { // Program entry point

cout << "hello, world" << endl; // Say Hello

return 0; // Terminate main()

} // End of main function

Step 2: Build the Executable Code: Compile and Link (aka Build) the source code "hello.cpp" into executable code ("hello.exe" in Windows or "hello" in UNIX/Linux/Mac).

On IDE (such as CodeBlocks), push the "Build" button.

On Text editor with the GNU GCC compiler, start a CMD Shell (Windows) or Terminal (UNIX/Linux/Mac) and issue these commands:

// Windows (CMD shell) - Build "hello.cpp" into "hello.exe"

> g++ -o hello.exe hello.cpp

// UNIX/Linux/Mac (Bash shell) - Build "hello.cpp" into "hello"

$ g++ -o hello hello.cpp

where g++ is the name of GCC C++ compiler; -o option specifies the output filename ("hello.exe" for Windows or "hello" for UNIX/Linux/Mac); "hello.cpp" is the input source file.

Step 3: Run the Executable Code: Execute (Run) the program.

On IDE (such as CodeBlocks), push the "Run" button.

On Text Editor with GNU GCC compiler, issue these command from CMD Shell (Windows) or Terminal (UNIX/Linux/Mac):

// Windows (CMD shell) - Run "hello.exe" (.exe is optional)

> hello

hello, world

// UNIX/Linux/Mac (Bash shell) - Run "hello" (./ denotes the current directory)

$ ./hello

hello, world

Similar questions