commit bd6e5e21ef41c9218cc4b02655c23b46cf20be38 Author: ZockerKatze Date: Tue Apr 29 12:55:37 2025 +0200 initial; learning so idk it will have many repos diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/implement.iml b/.idea/implement.iml new file mode 100644 index 0000000..cf84ae4 --- /dev/null +++ b/.idea/implement.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..d53e3f7 --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3ad48f7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..9f503eb --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "implement" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..85b983c --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "implement" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..0bfb516 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,111 @@ +// Define a structure to represent a class (Klasse) +struct Klasse { + name: String, // Name of the class + student_count: u32, // Number of students + teacher: String, // Name of the teacher + grade: f32, // Grade level or average + students: Vec, // List of student names + subjects: Vec, // List of subject names +} + +// Implement methods for the Klasse struct +impl Klasse { + // Constructor method to create a new Klasse with default values + fn new() -> Klasse { + Klasse { + name: String::new(), + student_count: 0, + teacher: String::new(), + grade: 0.0, + students: Vec::new(), // Correct: store students here + subjects: Vec::new(), + } + } + + // Add a student by name, update student count, and store the student name + fn add_student(&mut self, name: String) { + self.student_count += 1; + self.students.push(name); // Fixed: was wrongly pushing to subjects + } + + // Return the number of students + fn get_student_count(&self) -> u32 { + self.student_count + } + + // Return a list of students + fn get_students(&self) -> Vec { + self.students.clone() // Return a copy + } + + // Return a list of subjects + fn get_subjects(&self) -> Vec { + self.subjects.clone() + } + + // Add a subject + fn add_subject(&mut self, subject: String) { + self.subjects.push(subject); + } + + // Get the average grade or level + fn get_grade(&self) -> f32 { + self.grade + } + + // Set the average grade or level + fn set_grade(&mut self, grade: f32) { + self.grade = grade; + } + + // Get teacher's name + fn get_teacher(&self) -> String { + self.teacher.clone() + } + + // Set teacher's name + fn set_teacher(&mut self, teacher: String) { + self.teacher = teacher; + } + + // Get the class name + fn get_name(&self) -> String { + self.name.clone() + } + + // Set the class name + fn set_name(&mut self, name: String) { + self.name = name; + } + + // Display all class information + fn display(&self) { + println!("Class: {}", self.name); + println!("Teacher: {}", self.teacher); + println!("Grade: {}", self.grade); + println!("Number of students: {}", self.student_count); + println!("Students: {:?}", self.students); + println!("Subjects: {:?}", self.subjects); + } +} + +fn main() { + // Create a new class + let mut my_class = Klasse::new(); + + // Set class information + my_class.set_name("Class 1A".to_string()); + my_class.set_teacher("Ms. Smith".to_string()); + my_class.set_grade(3.8); + + // Add students + my_class.add_student("Alice".to_string()); + my_class.add_student("Bob".to_string()); + + // Add subjects + my_class.add_subject("Math".to_string()); + my_class.add_subject("Science".to_string()); + + // Display the class information + my_class.display(); +}