Stop being the product.
Become the owner.
or
sign uplog in
How is this simple student management system thing in C++?

Hey,

so I guess I kinda am a beginner programmer and here is a very basic student management/handling system I made in C++ (I coded this on my phone so I couldn't use text files to store data). Any suggestions on how to improve it and whatnot would be appreciated.

\`\`\`cpp

\#include <iostream>

# include <iomanip>

# include <string>

# include <vector>

# include <algorithm>

using namespace std; class Student { public: string name, className; double grade;

Student(string n, string cn, double g){
name = n;
className = cn;
grade = g;
}

bool isPassing (){
return grade >= 5;
}

};

void sortByGrade(vector<Student>& Students) { sort(Students.begin(), Students.end(), { return a.grade > b.grade; }); } int main() { vector<Student> Students = { {"Abigail Northfolk", "9A", 3.15}, {"Sam Alter", "5G", 4.9}, {"Victor Guzman", "12A", 4.3}, {"Joseph Pelter", "6B", 8.41}, {"Joseph Allende", "8A", 9.51}, {"Joe Bowler", "11C", 6.399}, {"Joe Wingham", "1A", 0}, {"Donald Pelter", "8C", 6.4}, }; double sum = 0; Student bestStudent = Students\[0\], worstStudent = Students\[0\]; sortByGrade (Students); for(int i = 0; i < Students.size(); i++){ if (Students\[i\].grade > 10) Students\[i\].grade = 10; if (Students\[i\].grade < 0) Students\[i\].grade = 0; if (Students\[i\].grade > bestStudent.grade) bestStudent = Students\[i\]; if (Students\[i\].grade < worstStudent.grade) worstStudent = Students\[i\]; sum += Students\[i\].grade; cout << Students\[i\].name << " (" << Students\[i\].className << "), grade: " << Students\[i\].grade << " - " << (Students\[i\].isPassing() ? "pass" : "fail") << endl; } cout << " " << endl; cout << "Average grade: " << fixed << setprecision(3) << sum / Students.size() << endl; cout << "Best student: " << bestStudent.name << " from " << bestStudent.className << " with a grade of " << bestStudent.grade << endl; cout << "Worst student: " << worstStudent.name << " from " << worstStudent.className << " with a grade of " << worstStudent.grade << endl; return 0; }

\`\`\`
#technology #dev #programming
source
im getting this error every time i run my code )

this is my code "first time coding"

#include <iostream>


int main() {
 
    std::cout << "i like pizza!" << std::endl;
    std::cout << "its really good!" << std::endl;
    return 0;
}

im on C++, OS ( Windows11 ), and im pretty sure that i downloaded my compiler i followed every step i saw on the video i watched

help :)
#dev #technology #programming
source
How to create an interactive shell mode

Hey there! I'm experimenting with POSIX api and I want to create my own mini shell. I want my shell to open an interactive shell mode and be able to receive command input line by line from the kernel. I am not sure how to achieve this. If I am not mistaken, I read that I should be able to somehow link my shell to a /dev/ttyX or /dev/pts/X driver in "cooked mode" (my shell only receives input only after a user presses 'ENTER', not after every keypress)

Ive tried Googling for the solution, but its been ineffective. Im so confused, I don't even know how to look for a solution for this.


Here is the current code snippet of my program. (Excuse the bad programming) `initInteractiveMode` is meant to initialize interactive mode

```
#include <stdio.h>
#include <string.h>
#include <termios.h>

#define VERSION "0.0.1"

int parseArguments(int argc, char *argv[]);
void help();
void initInteractiveMode();

int main(int argc, char *argv[]) {
if (argc < 2) {
printf("shell\n");
return 0;
}

if (!parseArguments(argc, argv)) {
return 0;
}

initInteractiveMode(); // Initialize Interactive Mode

printf("Chloe's shell interactive mode enabled\n\n");

while (1) {
}

return 0;
}

// TODO: Open interactive mode
void initInteractiveMode() {

}

int parseArguments(int argc, char *argv[]) {
const char *arg = argv[1];
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--version") == 0) {
printf("Chloe's shell, version %s\n", VERSION);
} else if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
help();
} else if (strcmp(arg, "interactive") == 0 || strcmp(arg, "i") == 0) {
return 1; // Enter interactive mode
} else {
printf("Invalid command\n\n");
help();
}

return 0;
}

void help() {
printf("Chloe's shell\n\n");
printf("\033[1mCommand:\033[0m shell [options]\n\n");
printf("List of options:\n");
printf("A simple shell for testing POSIX system calls\n");
printf("interactive\tEnter interactive mode\n");
printf("--help | -h\tDisplay help information\n");
printf("--version | -v\tDisplay version information\n");
}
```
#dev #programming #technology
source