MCPcopy Create free account
hub / github.com/Rustam-Z/cpp-programming / F_First_Program

Function F_First_Program

Lab_19/main.cpp:16–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14int main();
15
16void F_First_Program()
17{
18
19 // creating a text file one.txt
20 ofstream out_one;
21 out_one.open("one.txt");
22 for (int i = 2; i <= 2 * 10; i = i + 2)
23 {
24 out_one << i << endl; // writing to file first ten even numbers
25 }
26 out_one.close(); // closing the file
27
28 // creating a text file one.txt
29 ofstream out_two;
30 out_two.open("two.txt");
31 for (int i = 5; i <= 5 * 10; i = i + 5)
32 {
33 out_two << i << endl; // writing to file first ten multiples of five
34 }
35 out_two.close(); // closing the file
36
37 // calculting the sum
38 ifstream in_one;
39 ifstream in_two;
40 in_one.open("one.txt"); // opening files
41 in_two.open("two.txt");
42
43 int total = 0;
44 int num1 = 0;
45 int num2 = 0;
46
47 while (in_one && in_two)
48 {
49 total += num1 + num2; // calculating the total
50 in_one >> num1;
51 in_two >> num2;
52 }
53 in_one.close(); // closing the files
54 in_two.close();
55
56 ///////////////////////////////////////////////////////////////////
57 // creating a file total for storingthe total sum of numbers
58 ofstream out_total("total.txt");
59 out_total << total << endl;
60 out_total.close();
61
62 // reading the file and outputing it on the screen
63 ifstream in_total;
64 in_total.open("total.txt");
65
66 cout << "All three Files are created!\n";
67
68 in_total >> total;
69 cout << "TOTAL: " << total << "\n\n"; // displaying the total in console
70
71 in_total.close(); // closing the file after executing
72}
73

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected