This commit is contained in:
louiscklaw
2025-02-01 02:04:02 +08:00
parent 8bf2589af5
commit bfa5b5ff46
79 changed files with 4051 additions and 0 deletions

16
_prompts/step3/prompt.md Normal file
View File

@@ -0,0 +1,16 @@
write some cpp functions:
- User can add, edit and delete the record to the system manually or upload a file.
using cpp, write a console program that accepts:
user input a csv file path
the program then parse the inputted csv file and insert the record
```
name,maths,chinese,english
apple,99,98,99
banana,99,98,99
```

3
_prompts/step3/test.txt Normal file
View File

@@ -0,0 +1,3 @@
burger 15
fries 11
ice-cream 9

View File

@@ -0,0 +1,45 @@
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main(){
//Declare variables
ifstream inFile;
ofstream outFile;
string burger_name, fries_name, icecream_name;
int burger_price, fries_price, icecream_price;
//Open the input file and output file
inFile.open("price.txt");
if (!inFile) {
cout << "Cannot open the input file."
<< "The program terminates." << endl;
return 1;
}
outFile.open("price_output.out");
cout << "Processing data" << endl;
//Read file word by word
inFile >> burger_name >> burger_price;
inFile >> fries_name >> fries_price;
inFile >> icecream_name >> icecream_price;
//Output file
outFile << "The price of " << burger_name
<< " is $" << burger_price <<"." << endl;
outFile << "The price of " << fries_name
<< " is $" << fries_price << "." << endl;
outFile << "The price of " << icecream_name
<< " is $" << icecream_price << "." << endl;
inFile.close(); // .close(): close a file
outFile.close();
cout << "Processing completed" << endl;
return 0;
}