Programming Projects
1. The Secret Translator
The code(c++)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string reverseSentence(const string& input) {
string reversed = input;
reverse([Link](), [Link]());
return reversed;
}
int main() {
cout<<"This is our secret translator!"<<endl;
string sentence;
while (true) {
cout << "Enter a sentence: ";
getline(std::cin, sentence);
if (sentence == "exit") {
cout << "Goodbye!" << endl;
break;
}
string reversed = reverseSentence(sentence);
cout << "Reversed sentence: " << reversed << endl;
}
return 0;
}
Tips to use: Paste this code to an online compiler like Programiz(the link is
here: [Link]
Press run, Enter your sentence, see the backwards of your sentence and
copy and paste(Send your friend or maybe secret copine), when you’re
done type exit, then, it stops working.
2. Advanced Calculator!
The code(phyton)
import math
def calculator():
print("Welcome to the Advanced Calculator!")
while True:
operation = input("\nEnter operation: ").strip()
if [Link]() == 'quit':
print("Exiting the calculator. Goodbye!")
break
if operation in ['+', '-', '*', '/', '^']:
try:
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
if operation == '+':
result = num1 + num2
elif operation == '-':
result = num1 - num2
elif operation == '*':
result = num1 * num2
elif operation == '/':
if num2 == 0:
print("Error: Division by zero is not allowed.")
continue
result = num1 / num2
elif operation == '^':
result = num1 ** num2
print(f"The result is: {result}")
except ValueError:
print("Invalid input. Please enter numeric values.")
elif operation == 'sqrt':
try:
num = float(input("Enter the number: "))
if num < 0:
print("Error: Square root of a negative number is not defined for real numbers.")
continue
result = [Link](num)
print(f"The square root of {num} is: {result}")
except ValueError:
print("Invalid input. Please enter a numeric value.")
elif operation == 'root':
try:
num = float(input("Enter the number: "))
n = float(input("Enter the root (e.g., 2 for square root, 3 for cube root): "))
if n == 0:
print("Error: Root value cannot be zero.")
continue
if num < 0 and n % 2 == 0:
print("Error: Even root of a negative number is not defined for real numbers.")
continue
result = num ** (1 / n)
print(f"The {n}th root of {num} is: {result}")
except ValueError:
print("Invalid input. Please enter numeric values.")
else:
print("Invalid operation. Please try again.")
if __name__ == "__main__":
calculator()
Tips to use: Open compiler (online) again, this time choose phyton, paste
this code, enter the symbol of operation you want to work with, then enter
numbers, type quit to exit. Here’s the symbols of operations: Addition:
+,Subtraction: -,Multiplication: *, Division: /,Exponentiation:^ , Square
Root: sqrt, Nth Root: root.
3. Password generator
The code(c++)
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
string generatePassword(int length, bool includeSpecialChars) {
string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string specialCharacters = "!@#$%^&*()-_=+[{]}|;:,.<>?";
if (includeSpecialChars) {
characters += specialCharacters;
string password = "";
for (int i = 0; i < length; ++i) {
password += characters[rand() % [Link]()];
return password;
int main() {
srand(time(0));
cout << "Welcome to the Password Generator!\n";
int length;
cout << "Enter the desired password length: ";
cin >> length;
char includeSpecial;
cout << "Include special characters? (y/n): ";
cin >> includeSpecial;
bool includeSpecialChars = (includeSpecial == 'y' || includeSpecial == 'Y');
string password = generatePassword(length, includeSpecialChars);
cout << "\nYour generated password is: " << password << endl;
return 0;
Tips to use: Choose C++ from online compiler(like programiz) and then
copy this code and paste that into the compiler, write how many letters you
want in your password, and choose if you want special characters or not, to
choose type y or n, Y means “yep I want special characters”, N means “No
I don’t want”.