Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 65 additions & 65 deletions src/arithmetic/basic_arithmetic_ops/calculating_fractions.rs
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
use crate::arithmetic::basic_arithmetic_ops::index_operators::find_index;


// Diese Funktionen sind erstmal auf Eis gesetzt, weil es in meiner
// derzeitigen Entwicklung keinen richtigen Sinn macht, wenn ich zur
// Formelumstellung oder Formeln komme werde ich diese Funktionen als
// eigenes Modul für die Bruchrechnung verwenden und weiter ausbauen.

pub fn calculate_fraction(fractions: Vec<String>) -> Vec<String> {
let mut result_fraction: Vec<String> = fractions;
let mut index_brackets: Vec<(usize, usize)> = Vec::new();
let mut fractions_term: Vec<Bruch> = vec![];

println!("Vektor davor: {:?}", result_fraction);
parse_fractions(&mut result_fraction, &mut fractions_term);
println!("Vektor danach: {:?}", result_fraction);

index_brackets = find_index(&result_fraction);
println!("Index der Klammern: {:?}", index_brackets);

calculate_rules_fraction(&mut result_fraction, &mut fractions_term, &mut index_brackets);

//todo!("Noch im Bau! (calculate_fraction)");
return Vec::new()
}

struct Bruch {
numerator: i32,
denominator: i32,
}

// hier werden alle Brüche in einem Vektor gespeichert
fn parse_fractions(fractions: &mut Vec<String>, fractions_term: &mut Vec<Bruch>) {
let mut index: usize = 0;

while index < fractions.len() {
if fractions[index].contains("/") {
if fractions[index + 1] == "0" {
panic!("Division by Zero!")
}

let vec_fractions = Bruch {
numerator: fractions[index - 1].parse::<i32>().expect("invalid numerator"),
denominator: fractions[index + 1].parse::<i32>().expect("invalid numerator"),
};

fractions_term.push(vec_fractions);

// Hier werden die Brüche durch einen Marker ersetzt.
let index_bruch: String = "bruch_".to_string() + &((fractions_term.len()) - 1).to_string();
fractions.remove(index);
fractions.insert(index, index_bruch);
fractions.remove(index + 1);
fractions.remove(index - 1);
// use crate::arithmetic::basic_arithmetic_ops::index_operators::find_index;


// // Diese Funktionen sind erstmal auf Eis gesetzt, weil es in meiner
// // derzeitigen Entwicklung keinen richtigen Sinn macht, wenn ich zur
// // Formelumstellung oder Formeln komme werde ich diese Funktionen als
// // eigenes Modul für die Bruchrechnung verwenden und weiter ausbauen.
// #[warn(unused_assignments)]
// pub fn calculate_fraction(fractions: Vec<String>) -> Vec<String> {
// let mut result_fraction: Vec<String> = fractions;
// let mut index_brackets: Vec<(usize, usize)> = Vec::new();
// let mut fractions_term: Vec<Bruch> = vec![];

// println!("Vektor davor: {:?}", result_fraction);
// parse_fractions(&mut result_fraction, &mut fractions_term);
// println!("Vektor danach: {:?}", result_fraction);

// index_brackets = find_index(&result_fraction);
// println!("Index der Klammern: {:?}", index_brackets);

// calculate_rules_fraction(&mut result_fraction, &mut fractions_term, &mut index_brackets);

// //todo!("Noch im Bau! (calculate_fraction)");
// return Vec::new()
// }

// struct Bruch {
// numerator: i32,
// denominator: i32,
// }

// // hier werden alle Brüche in einem Vektor gespeichert
// fn parse_fractions(fractions: &mut Vec<String>, fractions_term: &mut Vec<Bruch>) {
// let mut index: usize = 0;

// while index < fractions.len() {
// if fractions[index].contains("/") {
// if fractions[index + 1] == "0" {
// panic!("Division by Zero!")
// }

// let vec_fractions = Bruch {
// numerator: fractions[index - 1].parse::<i32>().expect("invalid numerator"),
// denominator: fractions[index + 1].parse::<i32>().expect("invalid numerator"),
// };

// fractions_term.push(vec_fractions);

// // Hier werden die Brüche durch einen Marker ersetzt.
// let index_bruch: String = "bruch_".to_string() + &((fractions_term.len()) - 1).to_string();
// fractions.remove(index);
// fractions.insert(index, index_bruch);
// fractions.remove(index + 1);
// fractions.remove(index - 1);

}
index += 1;
}
}
// }
// index += 1;
// }
// }

fn calculate_rules_fraction(fractions: &mut Vec<String>, fractions_term: &mut Vec<Bruch>, index_brackets: &mut Vec<(usize, usize)>) {
let mut index: usize = 0;
// fn calculate_rules_fraction(fractions: &mut Vec<String>, fractions_term: &mut Vec<Bruch>, index_brackets: &mut Vec<(usize, usize)>) {
// let mut index: usize = 0;

while index < fractions.len() {
// while index < fractions.len() {


index += 1;
}
// index += 1;
// }

todo!("Noch im Bau (calculates_rules_fraction)!")
}
// todo!("Noch im Bau (calculates_rules_fraction)!")
// }
40 changes: 11 additions & 29 deletions src/arithmetic/basic_arithmetic_ops/calculation_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,17 @@ pub fn find_operators(numbers: &Vec<String>) -> Vec<OperatorInfo> {
];

for i in numbers.iter() {

if i.contains(operations[0].symbol) {
if operations[0].active == true { continue; }
operations[0].active = true;
}
if i.contains(operations[1].symbol) {
if operations[1].active == true { continue; }
operations[1].active = true;
}

else if i.contains(operations[2].symbol) {
if operations[2].active == true { continue; }
operations[2].active = true;
}
else if i.contains(operations[3].symbol) {
if operations[3].active == true { continue; }
operations[3].active = true;
}
else if i.contains(operations[4].symbol) {
if operations[4].active == true { continue; }
operations[4].active = true;
}
else if i.contains(operations[5].symbol) {
if operations[5].active == true { continue; }
operations[5].active = true;
}
else if i.contains(operations[6].symbol) {
if operations[6].active == true { continue; }
operations[6].active = true;
for c in i.chars() {
match c {
'/' => { operations[0].active = true; },
'(' => { operations[1].active = true; },
'^' => { operations[2].active = true; },
'*' => { operations[3].active = true; },
':' => { operations[4].active = true; },
'+' => { operations[5].active = true; },
'-' => { operations[6].active = true; },
_ => {}
}
}
}
return operations
Expand Down
13 changes: 8 additions & 5 deletions src/helping_tools/string_manipulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,26 @@ fn remove_whitespaces(with_whitespaces: &mut String) {
// und auf Vollständigkeit der Klammern.
fn validation_brackets_operators(brackets_ops: &mut String) {
let mut count_brackets: usize = 0;
//let brackets_ops_string: &String = brackets_ops;

// Das allererste Zeichen wird gelesen.
let first_char: char = brackets_ops.chars().nth(0).unwrap();

// Prüfen ob das erste Zeichen des Strings korrekt
// anfängt. Bei der Berechnung dürfen nur +, -, ( oder eine Zahl
// Bei der Berechnung dürfen nur +, -, ( oder eine Zahl
// den Anfang machen. Hier wird jeweils das Programm abgebrochen
// um sicher zu gehen das es nicht in einen inkonsistenten
// Zusatnd kommt.
// Zustand kommt.
if first_char == '-' || first_char == '+' || first_char.is_digit(10) || first_char == '(' {
for terms in brackets_ops.chars() {
if terms == ')' && count_brackets == 0 {
panic!("Darf nicht mit einer ')' Klammer beginnen")
}
if terms == '(' || terms == ')' {
if terms == '(' {
count_brackets += 1;
} else if terms == ')' {
if count_brackets == 0 {
panic!("Zu viele schließende Klammern");
}
count_brackets -= 1;
}
}
// prüfen ob die Klammern vollständig sind
Expand Down
11 changes: 1 addition & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![allow(dead_code)]

use arithmetic::basic_arithmetic_ops::calculation_rules::rules_for_calculation;
use helping_tools::display_terminal::display_terminals;
use menue::mathtool_menue_terminal;

mod paths;
Expand All @@ -16,14 +14,7 @@ fn main() {
// let equation_string: String = "100+2*2-2^5*8/9-12+5/2*8+12".to_string();
//let equation_string: String = "(3+2)^2 * (4 ^ (-3)) - 5 * (10 / (2 + 3)) + 8 ^ 2".to_string();
//let equation_string: String = "-(5-5)".to_string();
let equation_string: String = "-4 + 5/6 * (3/2 + 6 / 4) + 6 : (3/9 * 3/4 + 1)".to_string();
//let equation_string: String = "-4 + 5/6 * (3/2 + 6 / 4) + 6 : (3/9 * 3/4 + 1)".to_string();

mathtool_menue_terminal();

// println!();
// display_terminals("Original Formel".to_string(), &equation_string);

// let splitted_terms: Vec<String> = paths::str_manipulation::strings_refactor(equation_string);

// println!("Ergebnis: {:?}", rules_for_calculation(splitted_terms));
}
14 changes: 11 additions & 3 deletions src/menue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn mathtool_menue_terminal() {
let mut input: String = input_formula();

match input.as_str().trim() {
"y" | "Y" => { break; }
"q" | "Q" => { break; }
"1" => {
sub_menue_arithmetic();
}
Expand All @@ -30,15 +30,18 @@ pub fn mathtool_menue_terminal() {
fn main_print_menue() {
println!("Mathetool by Super(d/g)oof\n");
println!("(1). Arithmetik\n");
println!("Eingabe als Nummer, zum beenden (y/Y) eingeben.\n");
println!("Eingabe als Nummer, zum Beenden (q/Q) eingeben.\n");
print!("Ihre Eingabe: ");
}

fn sub_menue_arithmetic() {
let mut input: String = String::new();

loop {
clearscreen();

display_term_rules();

print!("Ihr Term: ");
input = input_formula();

Expand All @@ -55,10 +58,15 @@ fn sub_menue_arithmetic() {

input = input_formula();

match input.as_str() {
match input.as_str().trim() {
"b" | "B" => { break; }
"w" | "W" => { continue; }
_ => { print!("Ungültige Eingabe") }
}
}
}

fn display_term_rules() {
println!("Bei der Eingabe bitte darauf achten nur gültige Zeichen zu verwenden!\n");
println!("Gültige Eingaben sind: '+,-,*,/,:,^,(,)' und alle Zahlen!\n")
}