Browse Source

adjusted files main_taschenrechner.c , taschenrechner.h

remotes/origin/kabrel
Enrico Schellenberger 11 months ago
parent
commit
76616df9af
  1. 223
      src/main/c/main_taschenrechner.c
  2. 45
      src/main/c/taschenrechner.h

223
src/main/c/main_taschenrechner.c

@ -1,12 +1,229 @@
#include <stdio.h>
// #include <string.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "taschenrechner.h"
int add(int a, int b) {
doulbe add(doulbe a, doulbe b) {
return a + b;
}
doulbe minus (doulbe a, doulbe b){
return a - b;
}
doulbe multiply(doulbe a, doulbe b) {
return a * b;
}
doulbe divide(doulbe a, doulbe b) {
if (b == 0) {
return 0;
}
return a / b;
}
// Square root function
double squareRootFunction(double x) {
// Using the sqrt function from math.h
return sqrt(x);
}
//..
// Trigonometric functions
double sineFunction(double angle) {
// Convert degrees to radians for trigonometric functions
return sin(angle * M_PI / 180.0);
}
double cosineFunction(double angle) {
// Convert degrees to radians for trigonometric functions
return cos(angle * M_PI / 180.0);
}
double tangentFunction(double angle) {
// Convert degrees to radians for trigonometric functions
return tan(angle * M_PI / 180.0);
}
//..
// Logarithmic functions
double logarithmFunction(double x) {
// Logarithm with base 10
return log10(x);
}
double naturalLogarithmFunction(double x) {
// Natural logarithm (ln)
return log(x);
}
double logarithmBase2Function(double x) {
// Logarithm with base 2
return log2(x);
}
//..
// Exponential function
double exponentialFunction(double x) {
// Exponential function (e^x)
return exp(x);
}
// ..
// Bitwise AND function
int bitwiseAND(int num1, int num2) {
return num1 & num2;
}
// Bitwise OR function
int bitwiseOR(int num1, int num2) {
return num1 | num2;
}
// Bitwise XOR function
int bitwiseXOR(int num1, int num2) {
return num1 ^ num2;
}
//..
// scientificmode
int scientificMode(){
double num, result;
int choice;
printf("Enter a number: ");
scanf("%lf", &num); // scan the number from user
printf("Scientific mode Options:\n");
printf("1: Square root:\n");
printf("2: Exponential:\n");
printf("2: Logarithm:\n");
printf("4: Trigonomertic");
scanf("%d", &choice); // user choice
switch(choice) {
case 1: // Square root
break;
case 2: // Exponential
break;
case 3: // Logarithm
break;
case 4: // Trigonomertic
break;
default: printf("Invalid choice. Please try again.\n");
}
return result;
}
// graphMode
void graphMode() {
double x, y;
printf("Enter the range for x (start end step): ");
double x_start, x_end, x_step;
scanf("%lf %lf %lf", &x_start, &x_end, &x_step);
printf("\nGraph for the function y = sin(x):\n");
printf(" x\t| y\n");
printf("--------------\n");
for (x = x_start; x <= x_end; x += x_step) {
y = sin(x);
printf("%.2lf\t| %.2lf\n", x, y);
}
}
// Programming mode
void programmingMode() {
int num1, num2, result;
char operator;
printf("Enter first integer: ");
scanf("%d", &num1);
printf("Enter operator (+, -, *, /): ");
scanf(" %c", &operator);
printf("Enter second integer: ");
scanf("%d", &num2);
}
// Unit converter mode
void unitConverterMode() {
int choice;
double value, result;
printf("Unit Converter Mode:\n");
printf("1. Meter to Kilometer\n");
printf("2. Kilogram to Gram\n");
printf("3. Celsius to Fahrenheit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
printf("Enter the value to convert: ");
scanf("%lf", &value);
}
// change mode
int mode(int userChoice){
switch(userChoice) {
case 1:return 1; // Basic mode
break;
case 2:return 2; // Scientific mode (Trigonomertic functions, Logarithm and exponential functions.)
break;
case 3:return 3; // Graph mode (Draw and visualize functions.)
break;
case 4:return 4; // Programming mode (Binary , octal and hexadecimal )
break;
case 5:return 5; // Unit converter mode (length, weight volume etc.)
break;
case 0: return 0; // printf("Exiting the calculator.\n");
break;
default: return -1; // printf("Invalid choice. Please try again.\n");
}
}
// display the mode options:
int displayMenu(){
return a+b;
printf("\nCalculator Modes: \n");
printf("\n1: Basic Mode\n");
printf("\n2: Scientific Mode (Trigonomertic functions, Logarithm and exponential functions.)\n");
printf("\n3: Graph Mode (Draw and visualize functions.)\n");
printf("\n4: Programming Mode (Binary , octal and hexadecimal )\n");
printf("\n5: Unit converter Mode (length, weight volume etc.)\n");
printf("\n0: Exit calculator\n");
return 1; // return 1 to check if the function works
}

45
src/main/c/taschenrechner.h

@ -1,6 +1,49 @@
#ifndef TASCHENRECHNER_H
#define TASCHENRECHNER_H
int add(int a, int b);
doulbe add(doulbe a, doulbe b);
doulbe minus(doulbe a, doulbe b);
doulbe multiply(doulbe a, doulbe b);
doulbe divide(doulbe a, doulbe b);
// Square root function
double squareRootFunction(double x);
//..
// Trigonometric functions
double sineFunction(double angle);
double cosineFunction(double angle);
double tangentFunction(double angle);
//..
// Logarithmic functions
double logarithmFunction(double x);
double naturalLogarithmFunction(double x);
double logarithmBase2Function(double x);
//..
// Exponential function
double exponentialFunction(double x);
// ..
// Bitwise AND function
int bitwiseAND(int num1, int num2);
// Bitwise OR function
int bitwiseOR(int num1, int num2);
// Bitwise XOR function
int bitwiseXOR(int num1, int num2);
int mode(int userChoice);
int displayMenu();
#endif // TASCHENRECHNER_H
Loading…
Cancel
Save