mirror of
https://github.com/theoleuthardt/learningC.git
synced 2026-06-13 09:37:53 +00:00
Initial commit
This commit is contained in:
commit
826d4c8c9d
81 changed files with 7268 additions and 0 deletions
65
uebung7/uebung7_modules/geometrics.c
Normal file
65
uebung7/uebung7_modules/geometrics.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#include <math.h>
|
||||
|
||||
// Funktionen zur Berechnung der Oberfläche und des Volumens
|
||||
|
||||
// Quader
|
||||
double quaderTeilflaechen(double laenge, double breite, double hoehe) {
|
||||
double flaeche1 = laenge * breite; // Grundfläche
|
||||
double flaeche2 = laenge * hoehe; // Seitenfläche 1
|
||||
double flaeche3 = breite * hoehe; // Seitenfläche 2
|
||||
|
||||
return flaeche1 + 2 * (flaeche2 + flaeche3); // Gesamte Oberfläche
|
||||
}
|
||||
|
||||
double quaderOberflaeche(double laenge, double breite, double hoehe) {
|
||||
return 2 * (laenge * breite + laenge * hoehe + breite * hoehe);
|
||||
}
|
||||
|
||||
double quaderVolumen(double laenge, double breite, double hoehe) {
|
||||
return laenge * breite * hoehe;
|
||||
}
|
||||
|
||||
// Quadratische Pyramide
|
||||
double pyramideTeilflaechen(double seitenlaenge, double hoehe) {
|
||||
double grundflaeche = seitenlaenge * seitenlaenge; // Grundfläche
|
||||
double dreiecksflaeche = 0.5 * seitenlaenge * hoehe; // Dreiecksfläche (eine Seite der Pyramide)
|
||||
|
||||
return grundflaeche + 4 * dreiecksflaeche; // Gesamte Oberfläche
|
||||
}
|
||||
|
||||
double pyramideOberflaeche(double seitenlaenge, double hoehe) {
|
||||
return seitenlaenge * seitenlaenge + 2 * seitenlaenge * sqrt((seitenlaenge/2)*(seitenlaenge/2) + hoehe*hoehe);
|
||||
}
|
||||
|
||||
double pyramideVolumen(double seitenlaenge, double hoehe) {
|
||||
return (seitenlaenge * seitenlaenge * hoehe) / 3.0;
|
||||
}
|
||||
|
||||
// Kugel
|
||||
double kugelTeilflaechen(double radius) {
|
||||
return 4 * M_PI * radius * radius; // Gesamte Oberfläche
|
||||
}
|
||||
|
||||
double kugelOberflaeche(double radius) {
|
||||
return 4 * M_PI * radius * radius;
|
||||
}
|
||||
|
||||
double kugelVolumen(double radius) {
|
||||
return (4.0 / 3.0) * M_PI * radius * radius * radius;
|
||||
}
|
||||
|
||||
// Kegel
|
||||
double kegelTeilflaechen(double radius, double hoehe) {
|
||||
double grundflaeche = M_PI * radius * radius; // Grundfläche
|
||||
double mantelflaeche = M_PI * radius * sqrt(radius*radius + hoehe*hoehe); // Mantelfläche
|
||||
|
||||
return grundflaeche + mantelflaeche; // Gesamte Oberfläche
|
||||
}
|
||||
|
||||
double kegelOberflaeche(double radius, double hoehe) {
|
||||
return M_PI * radius * (radius + sqrt(hoehe*hoehe + radius*radius));
|
||||
}
|
||||
|
||||
double kegelVolumen(double radius, double hoehe) {
|
||||
return (M_PI * radius * radius * hoehe) / 3.0;
|
||||
}
|
||||
24
uebung7/uebung7_modules/geometrics.h
Normal file
24
uebung7/uebung7_modules/geometrics.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef GEOMETRICS_H
|
||||
#define GEOMETRICS_H
|
||||
|
||||
// Quader
|
||||
double quaderTeilflaechen(double laenge, double breite, double hoehe);
|
||||
double quaderOberflaeche(double laenge, double breite, double hoehe);
|
||||
double quaderVolumen(double laenge, double breite, double hoehe);
|
||||
|
||||
// Quadratische Pyramide
|
||||
double pyramideTeilflaechen(double seitenlaenge, double hoehe);
|
||||
double pyramideOberflaeche(double seitenlaenge, double hoehe);
|
||||
double pyramideVolumen(double seitenlaenge, double hoehe);
|
||||
|
||||
// Kugel
|
||||
double kugelTeilflaechen(double radius);
|
||||
double kugelOberflaeche(double radius);
|
||||
double kugelVolumen(double radius);
|
||||
|
||||
// Kegel
|
||||
double kegelTeilflaechen(double radius, double hoehe);
|
||||
double kegelOberflaeche(double radius, double hoehe);
|
||||
double kegelVolumen(double radius, double hoehe);
|
||||
|
||||
#endif //GEOMETRICS_H
|
||||
101
uebung7/uebung7_modules/list.c
Normal file
101
uebung7/uebung7_modules/list.c
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
#include "list.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct list{
|
||||
void *data;
|
||||
struct list *ptr;
|
||||
};
|
||||
|
||||
struct list *top = NULL;
|
||||
|
||||
int isEmpty(){
|
||||
return (top == NULL);
|
||||
}
|
||||
|
||||
void Add(void *data){
|
||||
struct list *temp = (struct list *) malloc(sizeof(struct list));
|
||||
temp->data = data;
|
||||
if(top == NULL){
|
||||
temp->ptr = NULL;
|
||||
top = temp;
|
||||
return;
|
||||
}
|
||||
temp->ptr = top;
|
||||
top = temp;
|
||||
}
|
||||
|
||||
void *Get(int index){
|
||||
if (top == NULL)
|
||||
return NULL;
|
||||
|
||||
struct list *temp = top;
|
||||
for (int i = 0; i <= index; i++) {
|
||||
if (temp == NULL){
|
||||
printf("Element ist nicht enthalten!");
|
||||
return NULL;
|
||||
} else if(i == index){
|
||||
return temp->data;
|
||||
} else{
|
||||
temp = temp->ptr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int Size(){
|
||||
if (isEmpty())
|
||||
return 0;
|
||||
|
||||
struct list *next = top->ptr;
|
||||
int size = 1;
|
||||
for (; next != NULL; next = next->ptr) {
|
||||
size++;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
int Contains(void *item){
|
||||
if (top == NULL) {
|
||||
return -1;
|
||||
}
|
||||
struct list *temp = top;
|
||||
for (int i = 0; i < Size(); i++) {
|
||||
if (temp == NULL){
|
||||
printf("Element ist nicht enthalten!");
|
||||
return -1;
|
||||
} else if(item == temp->data){
|
||||
return i;
|
||||
} else{
|
||||
temp = temp->ptr;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Remove(int index){
|
||||
if(isEmpty())
|
||||
return;
|
||||
|
||||
struct list *temp = top->ptr;
|
||||
struct list *next = top;
|
||||
|
||||
if(index == 0){
|
||||
free(top);
|
||||
top = temp;
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = 1; i <= index; i++){
|
||||
if (temp == NULL)
|
||||
return;
|
||||
else if (i == index){
|
||||
next->ptr = temp->ptr;
|
||||
free(temp);
|
||||
return;
|
||||
} else
|
||||
next = temp;
|
||||
temp = temp->ptr;
|
||||
}
|
||||
}
|
||||
11
uebung7/uebung7_modules/list.h
Normal file
11
uebung7/uebung7_modules/list.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef LIST_H
|
||||
#define LIST_H
|
||||
|
||||
int isEmpty();
|
||||
void Add(void *data);
|
||||
void *Get(int index);
|
||||
int Size();
|
||||
int Contains(void *item);
|
||||
void Remove(int index);
|
||||
|
||||
#endif //LIST_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue