initial; learning so idk it will have many repos

This commit is contained in:
ZockerKatze
2025-04-29 12:55:37 +02:00
commit bd6e5e21ef
9 changed files with 168 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

8
.idea/.gitignore generated vendored Normal file
View File

@@ -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

11
.idea/implement.iml generated Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

10
.idea/material_theme_project_new.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="userId" value="-23badf23:19681180681:-7ff2" />
</MTProjectMetadataState>
</option>
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/implement.iml" filepath="$PROJECT_DIR$/.idea/implement.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

7
Cargo.lock generated Normal file
View File

@@ -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"

6
Cargo.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
name = "implement"
version = "0.1.0"
edition = "2021"
[dependencies]

111
src/main.rs Normal file
View File

@@ -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<String>, // List of student names
subjects: Vec<String>, // 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<String> {
self.students.clone() // Return a copy
}
// Return a list of subjects
fn get_subjects(&self) -> Vec<String> {
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();
}