Files
ctdocpp/create-sample-project.sh
TIPC1110 a32f79f6d5 feat: Implement core functionality for DTC C/C++ IDE
- Added ProjectManager class to handle project operations including opening, closing, building, and running projects.
- Introduced SyntaxHighlighter class for syntax highlighting in C and C++ files.
- Developed TerminalWidget for command execution and output display.
- Created TextEditor with line numbering and auto-indentation features.
- Established main application entry point in main.cpp.
- Designed UI layout for MainWindow using Qt Designer.
2025-07-04 12:23:20 +07:00

207 lines
4.7 KiB
Bash
Executable File

#!/bin/bash
echo "🎯 Creating C++ sample project for testing DTC IDE..."
# Create sample project directory
mkdir -p /Users/dothanh1110/DTC/sample-cpp-project
cd /Users/dothanh1110/DTC/sample-cpp-project
# Create CMakeLists.txt
cat > CMakeLists.txt << 'EOF'
cmake_minimum_required(VERSION 3.20)
project(SampleApp VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Add executable
add_executable(sample-app
src/main.cpp
src/Calculator.cpp
)
# Include directories
target_include_directories(sample-app PRIVATE include)
# Install
install(TARGETS sample-app DESTINATION bin)
EOF
# Create directories
mkdir -p src include
# Create main.cpp
cat > src/main.cpp << 'EOF'
#include <iostream>
#include <string>
#include "Calculator.h"
int main() {
std::cout << "🧮 Welcome to Sample Calculator!" << std::endl;
Calculator calc;
// Test basic operations
std::cout << "Testing basic operations:" << std::endl;
std::cout << "5 + 3 = " << calc.add(5, 3) << std::endl;
std::cout << "10 - 4 = " << calc.subtract(10, 4) << std::endl;
std::cout << "6 * 7 = " << calc.multiply(6, 7) << std::endl;
std::cout << "15 / 3 = " << calc.divide(15, 3) << std::endl;
// Interactive mode
std::cout << "\n📱 Interactive Calculator (type 'quit' to exit):" << std::endl;
double a, b;
std::string operation;
while (true) {
std::cout << "Enter operation (add/sub/mul/div) or 'quit': ";
std::cin >> operation;
if (operation == "quit") {
break;
}
std::cout << "Enter first number: ";
std::cin >> a;
std::cout << "Enter second number: ";
std::cin >> b;
if (operation == "add") {
std::cout << "Result: " << calc.add(a, b) << std::endl;
} else if (operation == "sub") {
std::cout << "Result: " << calc.subtract(a, b) << std::endl;
} else if (operation == "mul") {
std::cout << "Result: " << calc.multiply(a, b) << std::endl;
} else if (operation == "div") {
std::cout << "Result: " << calc.divide(a, b) << std::endl;
} else {
std::cout << "Unknown operation!" << std::endl;
}
std::cout << std::endl;
}
std::cout << "👋 Goodbye!" << std::endl;
return 0;
}
EOF
# Create Calculator.h
cat > include/Calculator.h << 'EOF'
#pragma once
/**
* @brief Simple Calculator class for basic arithmetic operations
*/
class Calculator {
public:
/**
* @brief Add two numbers
* @param a First number
* @param b Second number
* @return Sum of a and b
*/
double add(double a, double b);
/**
* @brief Subtract two numbers
* @param a First number
* @param b Second number
* @return Difference of a and b
*/
double subtract(double a, double b);
/**
* @brief Multiply two numbers
* @param a First number
* @param b Second number
* @return Product of a and b
*/
double multiply(double a, double b);
/**
* @brief Divide two numbers
* @param a Dividend
* @param b Divisor
* @return Quotient of a and b
* @throws std::invalid_argument if b is zero
*/
double divide(double a, double b);
private:
static constexpr double EPSILON = 1e-9;
};
EOF
# Create Calculator.cpp
cat > src/Calculator.cpp << 'EOF'
#include "Calculator.h"
#include <stdexcept>
#include <cmath>
double Calculator::add(double a, double b) {
return a + b;
}
double Calculator::subtract(double a, double b) {
return a - b;
}
double Calculator::multiply(double a, double b) {
return a * b;
}
double Calculator::divide(double a, double b) {
if (std::abs(b) < EPSILON) {
throw std::invalid_argument("Division by zero is not allowed!");
}
return a / b;
}
EOF
# Create README.md
cat > README.md << 'EOF'
# Sample C++ Calculator Project
This is a sample C++ project for testing the DTC C/C++ IDE.
## Features
- Basic arithmetic operations (add, subtract, multiply, divide)
- Interactive calculator mode
- Error handling for division by zero
- Modern C++20 features
## Building
```bash
mkdir build && cd build
cmake ..
make
```
## Running
```bash
./sample-app
```
## Testing in DTC IDE
1. Open DTC C/C++ IDE
2. File → Open Project
3. Select this directory
4. Use Cmd+B to build
5. Use Cmd+R to run
EOF
echo "✅ Sample C++ project created at: /Users/dothanh1110/DTC/sample-cpp-project"
echo ""
echo "📖 To test with DTC IDE:"
echo " 1. Open the IDE: cd /Users/dothanh1110/DTC/ide-cpp && ./run.sh"
echo " 2. File → Open Project"
echo " 3. Select: /Users/dothanh1110/DTC/sample-cpp-project"
echo " 4. Build: Cmd+B"
echo " 5. Run: Cmd+R"