Skip to content

Commit 7eefadc

Browse files
Merge pull request #1 from Chau-Nguyen-Developer/readFile
Read file and do calculations.
2 parents a6d3259 + 749015a commit 7eefadc

File tree

7 files changed

+243
-0
lines changed

7 files changed

+243
-0
lines changed

.vscode/c_cpp_properties.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "windows-gcc-x64",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"compilerPath": "gcc",
9+
"cStandard": "${default}",
10+
"cppStandard": "${default}",
11+
"intelliSenseMode": "windows-gcc-x64",
12+
"compilerArgs": [
13+
""
14+
]
15+
}
16+
],
17+
"version": 4
18+
}

.vscode/launch.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "C/C++ Runner: Debug Session",
6+
"type": "cppdbg",
7+
"request": "launch",
8+
"args": [],
9+
"stopAtEntry": false,
10+
"externalConsole": true,
11+
"cwd": "c:/Users/DellC/OneDrive - Cal Poly Pomona/CPP Spring 2025/Numerical Method/Programming 4/Blue VS Code",
12+
"program": "c:/Users/DellC/OneDrive - Cal Poly Pomona/CPP Spring 2025/Numerical Method/Programming 4/Blue VS Code/build/Debug/outDebug",
13+
"MIMode": "gdb",
14+
"miDebuggerPath": "gdb",
15+
"setupCommands": [
16+
{
17+
"description": "Enable pretty-printing for gdb",
18+
"text": "-enable-pretty-printing",
19+
"ignoreFailures": true
20+
}
21+
]
22+
}
23+
]
24+
}

.vscode/settings.json

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"C_Cpp_Runner.cCompilerPath": "gcc",
3+
"C_Cpp_Runner.cppCompilerPath": "g++",
4+
"C_Cpp_Runner.debuggerPath": "gdb",
5+
"C_Cpp_Runner.cStandard": "",
6+
"C_Cpp_Runner.cppStandard": "",
7+
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat",
8+
"C_Cpp_Runner.useMsvc": false,
9+
"C_Cpp_Runner.warnings": [
10+
"-Wall",
11+
"-Wextra",
12+
"-Wpedantic",
13+
"-Wshadow",
14+
"-Wformat=2",
15+
"-Wcast-align",
16+
"-Wconversion",
17+
"-Wsign-conversion",
18+
"-Wnull-dereference"
19+
],
20+
"C_Cpp_Runner.msvcWarnings": [
21+
"/W4",
22+
"/permissive-",
23+
"/w14242",
24+
"/w14287",
25+
"/w14296",
26+
"/w14311",
27+
"/w14826",
28+
"/w44062",
29+
"/w44242",
30+
"/w14905",
31+
"/w14906",
32+
"/w14263",
33+
"/w44265",
34+
"/w14928"
35+
],
36+
"C_Cpp_Runner.enableWarnings": true,
37+
"C_Cpp_Runner.warningsAsError": false,
38+
"C_Cpp_Runner.compilerArgs": [],
39+
"C_Cpp_Runner.linkerArgs": [],
40+
"C_Cpp_Runner.includePaths": [],
41+
"C_Cpp_Runner.includeSearch": [
42+
"*",
43+
"**/*"
44+
],
45+
"C_Cpp_Runner.excludeSearch": [
46+
"**/build",
47+
"**/build/**",
48+
"**/.*",
49+
"**/.*/**",
50+
"**/.vscode",
51+
"**/.vscode/**"
52+
],
53+
"C_Cpp_Runner.useAddressSanitizer": false,
54+
"C_Cpp_Runner.useUndefinedSanitizer": false,
55+
"C_Cpp_Runner.useLeakSanitizer": false,
56+
"C_Cpp_Runner.showCompilationTime": false,
57+
"C_Cpp_Runner.useLinkTimeOptimization": false,
58+
"C_Cpp_Runner.msvcSecureNoWarnings": false,
59+
"files.associations": {
60+
"atomic": "cpp",
61+
"bit": "cpp",
62+
"cctype": "cpp",
63+
"charconv": "cpp",
64+
"clocale": "cpp",
65+
"cmath": "cpp",
66+
"compare": "cpp",
67+
"concepts": "cpp",
68+
"cstddef": "cpp",
69+
"cstdint": "cpp",
70+
"cstdio": "cpp",
71+
"cstdlib": "cpp",
72+
"cstring": "cpp",
73+
"ctime": "cpp",
74+
"cwchar": "cpp",
75+
"exception": "cpp",
76+
"format": "cpp",
77+
"fstream": "cpp",
78+
"initializer_list": "cpp",
79+
"ios": "cpp",
80+
"iosfwd": "cpp",
81+
"iostream": "cpp",
82+
"istream": "cpp",
83+
"iterator": "cpp",
84+
"limits": "cpp",
85+
"locale": "cpp",
86+
"memory": "cpp",
87+
"new": "cpp",
88+
"ostream": "cpp",
89+
"sstream": "cpp",
90+
"stdexcept": "cpp",
91+
"streambuf": "cpp",
92+
"string": "cpp",
93+
"system_error": "cpp",
94+
"tuple": "cpp",
95+
"type_traits": "cpp",
96+
"typeinfo": "cpp",
97+
"utility": "cpp",
98+
"vector": "cpp",
99+
"xfacet": "cpp",
100+
"xiosbase": "cpp",
101+
"xlocale": "cpp",
102+
"xlocbuf": "cpp",
103+
"xlocinfo": "cpp",
104+
"xlocmes": "cpp",
105+
"xlocmon": "cpp",
106+
"xlocnum": "cpp",
107+
"xloctime": "cpp",
108+
"xmemory": "cpp",
109+
"xstring": "cpp",
110+
"xtr1common": "cpp",
111+
"xutility": "cpp"
112+
}
113+
}

input.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1 1.5 0 2
2+
3 3.25 3 1.67

programming4.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//PROGRAMMER: Ngoc Chau Nguyen
2+
//DATE: 2025-04-23
3+
//DESCRIPTION: This program is a simple C++ program that prints "Hello, World!" to the console.
4+
//ASSISTANT: CHAT GPT and classmate Jasper Liu
5+
6+
#include <iostream> //do I need it?
7+
#include <fstream>
8+
#include <sstream> //string stream -- allows me to treat a string as if it is a stream
9+
#include <vector>
10+
11+
12+
int main()
13+
{
14+
//Read two lines of numbers in input.txt and store them into two vectors
15+
//std::ifstream -- standard input file stream. Read data from a file.
16+
std::ifstream inputFile("input.txt");
17+
std::string line;
18+
std::vector<double> vector1;
19+
std::vector<double> vector2;
20+
21+
22+
if(inputFile.is_open())
23+
{
24+
//Read the first line into first vector.
25+
//(Use while loop if want to read continuously)
26+
27+
if(std::getline(inputFile, line))
28+
//getline function reads an entire line of text from a stream
29+
//(in this case, that stream is inputFile)
30+
{
31+
std::stringstream ss(line); //treat string like a stream. Able to extract tokens using >>.
32+
double number;
33+
while(ss >> number)
34+
{
35+
vector1.push_back(number);
36+
}
37+
38+
}
39+
40+
//Read the second line //A few thought: maybe create a separate function to read each line
41+
if(std::getline(inputFile, line))
42+
{
43+
std::stringstream ss(line);
44+
double number;
45+
while(ss >> number)
46+
{
47+
vector2.push_back(number);
48+
}
49+
}
50+
51+
inputFile.close(); //closes the file
52+
}
53+
else
54+
{
55+
std::cout << "File could not be opened!" << std::endl;
56+
}
57+
58+
//Print out vectors to check.
59+
std::cout << "x f[] f[,] f[, ,]" << std::endl;
60+
61+
for(size_t i = 0; i < vector1.size(); ++i)
62+
{
63+
std::cout << vector1[i] << " " << vector2[i] << std::endl;
64+
65+
}
66+
67+
std::vector<double> vector3;
68+
std::cout << "This is vector 3" << std::endl;
69+
for(size_t i = 1; i < vector1.size(); ++i)
70+
{
71+
std::cout << (vector2[i] - vector2[i-1]) / (vector1[i] - vector1[i-1]) << std::endl;
72+
}
73+
74+
std::vector<double> vector4;
75+
std::cout << "This is vector 4" << std::endl;
76+
std::cout <<"print out"<< std::endl;
77+
78+
for(size_t i = 1; i < vector3.size(); ++i)
79+
{
80+
std::cout << (vector3[i] - vector3[i-1]) / (vector1[i+1] - vector1[i-1]) << std::endl;
81+
}
82+
83+
84+
return 0;
85+
86+
}

programming4.exe

251 KB
Binary file not shown.

programming4.obj

229 KB
Binary file not shown.

0 commit comments

Comments
 (0)