Compare commits

..

1 Commits

Author SHA1 Message Date
pecp45i32 d757077c8a Add 1234
2 weeks ago

@ -0,0 +1 @@
undefined

@ -1,91 +0,0 @@
#include <stdio.h>
#define COL 4
#define GRADEBINGIN 1
int studentMember = 0;
double storeInformation[100][COL];
void inputStudentInformation(double store[][COL])
{
double* p;
int i = 0, j = 0;
while (1) {
p = &store[i][j];
double temp;
scanf("%lf", &temp);
*p = temp;
j++;
if (j == COL) {
printf("One student's information has been, input 0 or 1 to quit or continue.\n");
int ch;
scanf("%d", &ch);
if (ch == 0) { break; }
else if (ch == 1)
{
j = 0;
i++;
studentMember++;
}
else {
printf("WRONG INPUT,aoto quit\n");
break;
}
}
}
}
double sumScore(double store[][COL], int n) {
double sum = 0;
for (int i = GRADEBINGIN; i < COL; i++) {
sum += store[n][i];
}
return sum;
}
void printStudentOriginalScore(double store[][COL])
{
for (int i = 0; i <= studentMember; i++) {
printf("%5d %.1f %.1f %.1f %.1f\n", (int)store[i][0], store[i][1], store[i][2], store[i][3], sumScore(store, i));
}
}
void printstep2(double store[][COL]) {
for (int i = 0; i <= studentMember; i++) {
printf("%5d,%.1f,%.1f\n", (int)storeInformation[i][0], sumScore(storeInformation, i), sumScore(storeInformation, i) / 3);
}
}
void manage()
{
printf(" 1.Input\n");
printf(" 2.Output\n");
printf(" 3.Order\n");
printf(" 4.Quit\n");
char keywords;
keywords = getchar();
switch (keywords) {
case 'i':
printf("Please input info of the three students\n");
inputStudentInformation(storeInformation);
break;
case 'o':
printf("You are trying to Output info\n");
break;
case 'm':
printf("You are trying to Make things ordered\n");
break;
case 'q':
printf("You are about to Quit\n");
break;
default:
printf("Wrong input\n");
break;
}
}
int main()
{
manage();
printstep2(storeInformation);
return 0;
}

@ -1,270 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int studentMember = 7;
typedef struct storeInformation
{
char stus[100];
int classes;
char names[100];
double mathGrade;
double physicsGrade;
double englishGrade;
int boolNew;
} stu;
stu studentInformation[100] = {
{ "10001", 11, "Zhang", 99.5, 88.5, 89.5, 0 },
{ "10002", 12, "Yang", 77.9, 56.5, 87.5, 0 },
{ "10003", 11, "Liang", 92.5, 99.0, 60.0, 0 },
{ "10004", 11, "Cai", 89.6, 56.9, 90.5, 0 },
{ "10005", 14, "Fu", 55.6, 67.9, 98.9, 0 },
{ "10006", 12, "Mao", 22.1, 45.9, 99.2, 0 },
{ "10007", 13, "Zhan", 35.6, 67.9, 88.0, 0 }
};
void input(int i) {
scanf("%s", studentInformation[i].stus);
scanf("%d", &studentInformation[i].classes);
scanf("%s", studentInformation[i].names);
scanf("%lf", &studentInformation[i].mathGrade);
scanf("%lf", &studentInformation[i].physicsGrade);
scanf("%lf", &studentInformation[i].englishGrade);
}
void inputStudentInformation(int n) {
for (int i = 0; i < n; i++) {
input(i);
studentMember++;
studentInformation[i].boolNew = 0;
printf("One student has been input!\n");
}
}
void insertedNew() {
int i = studentMember;
input(i);
studentMember++;
studentInformation[i].boolNew = 1;
printf("One student has been input!\n");
}
void informationClear(char a[100]) {
int i = 0;
for (i = 0; i < studentMember; i++) {
if (strcmp(a, studentInformation[i].stus) == 0 || strcmp(a, studentInformation[i].names) == 0) {
memset(&studentInformation[i], 0, sizeof(studentInformation[i]));
}
}
}
void sortStudents() {
for (int i = 0; i < studentMember - 1; i++) {
for (int j = 0; j < studentMember - i - 1; j++) {
double totalScoreJ = studentInformation[j].mathGrade + studentInformation[j].physicsGrade + studentInformation[j].englishGrade;
double totalScoreJ1 = studentInformation[j + 1].mathGrade + studentInformation[j + 1].physicsGrade + studentInformation[j + 1].englishGrade;
if (studentInformation[j].classes > studentInformation[j + 1].classes ||
(studentInformation[j].classes == studentInformation[j + 1].classes && totalScoreJ < totalScoreJ1)) {
stu temp = studentInformation[j];
studentInformation[j] = studentInformation[j + 1];
studentInformation[j + 1] = temp;
}
}
}
printf("Students have been sorted!\n");
}
void printStudentOriginalScore() {
sortStudents();
int classs = 0;
for (int i = 0; i < studentMember; i++) {
if (studentInformation[i].classes != 0) {
if (studentInformation[i].classes != classs) {
printf("%d %s %s %.1f %.1f %.1f %s\n",
studentInformation[i].classes,
studentInformation[i].stus,
studentInformation[i].names,
studentInformation[i].mathGrade,
studentInformation[i].physicsGrade,
studentInformation[i].englishGrade,
studentInformation[i].boolNew == 0 ? "" : studentInformation[i].boolNew == 1 ? "inserted" : "modified");
}
else {
printf(" %s %s %.1f %.1f %.1f %s\n",
studentInformation[i].stus,
studentInformation[i].names,
studentInformation[i].mathGrade,
studentInformation[i].physicsGrade,
studentInformation[i].englishGrade,
studentInformation[i].boolNew == 0 ? "" : studentInformation[i].boolNew == 1 ? "inserted" : "modified");
}
classs = studentInformation[i].classes;
studentInformation[i].boolNew = 0;
}
}
}
void modifyStudent() {
char a[10];
printf("Are you sure(yes/no)");
scanf("%s", &a);
if ((strcmp(a, "yes")) == 0) {
char stusToModify[10];
printf("Enter the student number to modify, followed by new data ( 10001 2 Kobe 59 59 59):\n");
scanf("%s", stusToModify);
int found = 0;
for (int i = 0; i < studentMember; i++) {
if (strcmp(studentInformation[i].stus, stusToModify) == 0) {
found = 1;
scanf("%d %s %lf %lf %lf",
&studentInformation[i].classes,
studentInformation[i].names,
&studentInformation[i].mathGrade,
&studentInformation[i].physicsGrade,
&studentInformation[i].englishGrade);
studentInformation[i].boolNew = 2;
printf("Student data modified successfully!\n");
break;
}
}
if (!found) {
printf("Student with number %s not found.\n", stusToModify);
}
}
}
void queryByClassRange(int startClass, int endClass) {
printf("Students in classes %d to %d:\n", startClass, endClass);
for (int i = 0; i < studentMember; i++) {
if (studentInformation[i].classes >= startClass && studentInformation[i].classes <= endClass) {
printf("%s %d %s %.1f %.1f %.1f\n",
studentInformation[i].stus, studentInformation[i].classes, studentInformation[i].names,
studentInformation[i].mathGrade, studentInformation[i].physicsGrade, studentInformation[i].englishGrade);
}
}
}
void queryByIDRange(char startID[10], char endID[10]) {
printf("Students with IDs %s to %s:\n", startID, endID);
for (int i = 0; i < studentMember; i++) {
if (strcmp(studentInformation[i].stus, startID) >= 0 &&
strcmp(studentInformation[i].stus, endID) <= 0) {
printf("%s %d %s %.1f %.1f %.1f\n",
studentInformation[i].stus, studentInformation[i].classes, studentInformation[i].names,
studentInformation[i].mathGrade, studentInformation[i].physicsGrade, studentInformation[i].englishGrade);
}
}
}
void queryByNamePrefix(const char* prefix) {
printf("Students with names starting with %s:\n", prefix);
for (int i = 0; i < studentMember; i++) {
if (strncmp(studentInformation[i].names, prefix, strlen(prefix)) == 0) {
printf("%s %d %s %.1f %.1f %.1f\n",
studentInformation[i].stus, studentInformation[i].classes, studentInformation[i].names,
studentInformation[i].mathGrade, studentInformation[i].physicsGrade, studentInformation[i].englishGrade);
}
}
}
void queryByTotalScore(double threshold) {
printf("Students with total score >= %.1f:\n", threshold);
for (int i = 0; i < studentMember; i++) {
double totalScore = studentInformation[i].mathGrade + studentInformation[i].physicsGrade + studentInformation[i].englishGrade;
if (totalScore >= threshold) {
printf("%s %d %s %.1f %.1f %.1f\n",
studentInformation[i].stus, studentInformation[i].classes, studentInformation[i].names,
studentInformation[i].mathGrade, studentInformation[i].physicsGrade, studentInformation[i].englishGrade);
}
}
}
void queryByClassAndIDRange(int classNum, char startID[10], char endID[10]) {
printf("Students in class %d with IDs %s to %s:\n", classNum, startID, endID);
for (int i = 0; i < studentMember; i++) {
if (studentInformation[i].classes == classNum &&
strcmp(studentInformation[i].stus, startID) >= 0 &&
strcmp(studentInformation[i].stus, endID) <= 0) {
printf("%s %d %s %.1f %.1f %.1f\n",
studentInformation[i].stus, studentInformation[i].classes, studentInformation[i].names,
studentInformation[i].mathGrade, studentInformation[i].physicsGrade, studentInformation[i].englishGrade);
}
}
}
void handleInput() {
int queryType;
printf("Enter query type (1-5): ");
scanf("%d", &queryType);
if (queryType == 1) {
int startClass, endClass;
printf("Enter class range (start end): ");
scanf("%d %d", &startClass, &endClass);
queryByClassRange(startClass, endClass);
}
else if (queryType == 2) {
char startID[10], endID[10];
printf("Enter ID range (start end): ");
scanf("%s %s", startID, endID);
queryByIDRange(startID, endID);
}
else if (queryType == 3) {
char prefix[10];
printf("Enter name prefix: ");
scanf("%s", prefix);
queryByNamePrefix(prefix);
}
else if (queryType == 4) {
double threshold;
printf("Enter total score threshold: ");
scanf("%lf", &threshold);
queryByTotalScore(threshold);
}
else if (queryType == 5) {
int classNum;
char startID[10], endID[10];
printf("Enter class and ID range (class startID endID): ");
scanf("%d %s %s", &classNum, startID, endID);
queryByClassAndIDRange(classNum, startID, endID);
}
else {
printf("Invalid query type.\n");
}
}
void manage() {
printf(" 1.Input\n");
printf(" 2.Output\n");
printf(" 3.Order\n");
printf(" 4.Quit\n");
char keywords;
keywords = getchar();
switch (keywords) {
case 'i':
printf("Please input info of the three students\n");
inputStudentInformation(3);
break;
case 'o':
printf("You are trying to Output info\n");
break;
case 'm':
printf("You are trying to Make things ordered\n");
break;
case 'q':
printf("You are about to Quit\n");
break;
default:
printf("Wrong input\n");
break;
}
}
int main() {
handleInput();
return 0;
}

@ -1,33 +0,0 @@
#include <stdio.h>
void manage()//¹ÜÀíÖ÷Ì庯Êý
{
printf(" 1.Input\n");
printf(" 2.Output\n");
printf(" 3.Order\n");
printf(" 4.Quit\n");
char keywords;
keywords = getchar();
switch (keywords) {
case 'i':
printf("You are trying to Input info\n");
break;
case 'o':
printf("You are trying to Output info\n");
break;
case 'm':
printf("You are trying to Make things ordered\n");
break;
case 'q':
printf("You are about to Quit\n");
break;
default:
printf("Wrong input\n");
break;
}
}
int main()
{
manage();
return 0;
}

@ -1,85 +0,0 @@
#include <stdio.h>
#define COL 4
int studentMember = 0;
void inputStudentInformation(double store[][COL])
{
double* p;
int i = 0, j = 0;
while (1) {
p = &store[i][j];
double temp;
scanf("%lf", &temp);
*p = temp;
j++;
if (j == COL) {
printf("One student's information has been, input 0 or 1 to quit or continue.\n");
int ch;
scanf("%d", &ch);
if (ch == 0) { break; }
else if (ch == 1)
{
j = 0;
i++;
studentMember++;
}
else {
printf("WRONG INPUT,aoto quit\n");
break;
}
}
}
}
double sumScore(double store[][COL], int n) {
double sum = 0;
for (int i = 1; i < COL; i++) {
sum += store[n][i];
}
return sum;
}
void printStudentOriginalScore(double store[][COL])
{
for (int i = 0; i <= studentMember; i++) {
printf("%5d %.1f %.1f %.1f %.1f\n", (int)store[i][0], store[i][1], store[i][2], store[i][3], sumScore(store, i));
}
}
void manage()
{
printf(" 1.Input\n");
printf(" 2.Output\n");
printf(" 3.Order\n");
printf(" 4.Quit\n");
char keywords;
keywords = getchar();
switch (keywords) {
case 'i':
printf("You are trying to Input info\n");
break;
case 'o':
printf("You are trying to Output info\n");
break;
case 'm':
printf("You are trying to Make things ordered\n");
break;
case 'q':
printf("You are about to Quit\n");
break;
default:
printf("Wrong input\n");
break;
}
}
int main()
{
double* p, storeInformation[100][COL];
inputStudentInformation(storeInformation);
printStudentOriginalScore(storeInformation);
//manage();
return 0;
}

@ -1,106 +0,0 @@
#include <stdio.h>
#define COL 6
#define GRADEBINGIN 2
int studentMember = 0;
double storeInformation[100][COL];
void inputStudentInformation(double store[][COL])
{
double* p;
int i = 0, j = 0;
while (1) {
p = &store[i][j];
double temp;
scanf("%lf", &temp);
*p = temp;
j++;
if (j == COL - 1) {
*(p + 1) = 0;
printf("One student's information has been, input 0 or 1 to quit or continue.\n");
int ch;
scanf("%d", &ch);
if (ch == 0) { break; }
else if (ch == 1)
{
j = 0;
i++;
studentMember++;
}
else {
printf("WRONG INPUT,aoto quit\n");
break;
}
}
}
}
double sumScore(double store[][COL], int n) {
double sum = 0;
for (int i = GRADEBINGIN; i < COL - 1; i++) {
sum += store[n][i];
}
return sum;
}
void printStudentOriginalScore(double store[][COL])
{
for (int i = 0; i <= studentMember; i++) {
printf("%5d %d %.1f %.1f %.1f %.1f %s\n", (int)store[i][0], (int)store[i][1], store[i][2], store[i][3], store[i][4], sumScore(store, i), store[i][6] == 1? "":"inserted");
}
}
void printstep2(double store[][COL]) {
for (int i = 0; i <= studentMember; i++) {
printf("%5d,%.1f,%.1f\n", (int)storeInformation[i][0], sumScore(storeInformation, i), sumScore(storeInformation, i) / 3);
}
}
void insertedNew() {
printf("The new student information\n");
studentMember++;
double* p;
for (int i = 0; i < COL - 1; i++) {
p = &storeInformation[studentMember][i];
double temp = 0;
scanf("%lf", &temp);
*p = temp;
}
*(p + 1) = 1;
}
void manage()
{
printf(" 1.Input\n");
printf(" 2.Output\n");
printf(" 3.Order\n");
printf(" 4.Quit\n");
char keywords;
keywords = getchar();
switch (keywords) {
case 'i':
printf("Please input info of the three students\n");
inputStudentInformation(storeInformation);
break;
case 'o':
printf("You are trying to Output info\n");
break;
case 'm':
printf("You are trying to Make things ordered\n");
break;
case 'q':
printf("You are about to Quit\n");
break;
default:
printf("Wrong input\n");
break;
}
}
int main()
{
manage();
insertedNew();
printStudentOriginalScore(storeInformation);
return 0;
}

@ -1,101 +0,0 @@
#include <stdio.h>
#include <string.h>
int studentMember = 0;
typedef struct storeInformation
{
char stus[100];
int classes;
char names[100];
double mathGrade;
double physicsGrade;
double englishGrade;
int boolNew;
}stu;
stu studentInformation[100];
void inputStudentInformation(int n)
{
for (int i = 0; i < n; i++) {
scanf("%s", studentInformation[i].stus);
scanf("%d", &studentInformation[i].classes);
scanf("%s", studentInformation[i].names);
scanf("%lf", &studentInformation[i].mathGrade);
scanf("%lf", &studentInformation[i].physicsGrade);
scanf("%lf", &studentInformation[i].englishGrade);
studentMember++;
studentInformation[i].boolNew = 0;
printf("One student has been input!\n");
}
}
void insertedNew() {
int i = studentMember;
scanf("%s", studentInformation[i].stus);
scanf("%d", &studentInformation[i].classes);
scanf("%s", studentInformation[i].names);
scanf("%lf", &studentInformation[i].mathGrade);
scanf("%lf", &studentInformation[i].physicsGrade);
scanf("%lf", &studentInformation[i].englishGrade);
studentMember++;
studentInformation[i].boolNew = 1;
printf("One student has been input!\n");
}
void printStudentOriginalScore() {
for (int i = 0; i < studentMember; i++) {
if (studentInformation[i].stus != 0) {
printf("%s %d %s %.1f %.1f %.1f %s\n", studentInformation[i].stus, studentInformation[i].classes, studentInformation[i].names, studentInformation[i].mathGrade, studentInformation[i].physicsGrade, studentInformation[i].englishGrade, studentInformation[i].boolNew == 0 ? "" : "inserted");
}
}
}
void informationClear(char a[100]) {
int i = 0;
for (i = 0; i < studentMember; i++) {
if (strcmp(a, studentInformation[i].stus) == 0 || strcmp(a, studentInformation[i].names) == 0) {
memset(&studentInformation[i], 0, sizeof(studentInformation[i]));
}
}
}
void manage()
{
printf(" 1.Input\n");
printf(" 2.Output\n");
printf(" 3.Order\n");
printf(" 4.Quit\n");
char keywords;
keywords = getchar();
switch (keywords) {
case 'i':
printf("Please input info of the three students\n");
inputStudentInformation(3);
break;
case 'o':
printf("You are trying to Output info\n");
break;
case 'm':
printf("You are trying to Make things ordered\n");
break;
case 'q':
printf("You are about to Quit\n");
break;
default:
printf("Wrong input\n");
break;
}
}
int main()
{
char a[100];
manage();
printf("Enter your clear student.\n");
scanf("%s", &a);
informationClear(a);
printStudentOriginalScore();
return 0;
}

@ -1,166 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int studentMember = 0;
typedef struct storeInformation
{
char stus[10];
int classes;
char names[10];
double mathGrade;
double physicsGrade;
double englishGrade;
int boolNew;
} stu;
stu studentInformation[10];
void input(int i) {
scanf("%s", studentInformation[i].stus);
scanf("%d", &studentInformation[i].classes);
scanf("%s", studentInformation[i].names);
scanf("%lf", &studentInformation[i].mathGrade);
scanf("%lf", &studentInformation[i].physicsGrade);
scanf("%lf", &studentInformation[i].englishGrade);
}
void inputStudentInformation(int n) {
for (int i = 0; i < n; i++) {
input(i);
studentMember++;
studentInformation[i].boolNew = 0;
printf("One student has been input!\n");
}
}
void insertedNew() {
int i = studentMember;
input(i);
studentMember++;
studentInformation[i].boolNew = 1;
printf("One student has been input!\n");
}
void informationClear(char a[100]) {
int i = 0;
for (i = 0; i < studentMember; i++) {
if (strcmp(a, studentInformation[i].stus) == 0 || strcmp(a, studentInformation[i].names) == 0) {
memset(&studentInformation[i], 0, sizeof(studentInformation[i]));
}
}
}
void sortStudents() {
for (int i = 0; i < studentMember - 1; i++) {
for (int j = 0; j < studentMember - i - 1; j++) {
double totalScoreJ = studentInformation[j].mathGrade + studentInformation[j].physicsGrade + studentInformation[j].englishGrade;
double totalScoreJ1 = studentInformation[j + 1].mathGrade + studentInformation[j + 1].physicsGrade + studentInformation[j + 1].englishGrade;
if (studentInformation[j].classes > studentInformation[j + 1].classes ||
(studentInformation[j].classes == studentInformation[j + 1].classes && totalScoreJ < totalScoreJ1)) {
stu temp = studentInformation[j];
studentInformation[j] = studentInformation[j + 1];
studentInformation[j + 1] = temp;
}
}
}
printf("Students have been sorted!\n");
}
void printStudentOriginalScore() {
sortStudents();
int classs = 0;
for (int i = 0; i < studentMember; i++) {
if (studentInformation[i].classes != 0) {
if (studentInformation[i].classes == classs) {
printf("%d %s %s %.1f %.1f %.1f %s\n",
studentInformation[i].classes,
studentInformation[i].stus,
studentInformation[i].names,
studentInformation[i].mathGrade,
studentInformation[i].physicsGrade,
studentInformation[i].englishGrade,
studentInformation[i].boolNew == 0 ? "" : studentInformation[i].boolNew == 1 ? "inserted" : "modified");
}
else {
printf(" %s %s %.1f %.1f %.1f %s\n",
studentInformation[i].stus,
studentInformation[i].names,
studentInformation[i].mathGrade,
studentInformation[i].physicsGrade,
studentInformation[i].englishGrade,
studentInformation[i].boolNew == 0 ? "" : studentInformation[i].boolNew == 1 ? "inserted" : "modified");
}
classs = studentInformation[i].classes;
studentInformation[i].boolNew = 0;
}
}
}
void modifyStudent() {
char a[10];
printf("Are you sure(yes/no)");
scanf("%s", &a);
if ((strcmp(a, "yes")) == 0) {
char stusToModify[10];
printf("Enter the student number to modify, followed by new data ( 10001 2 Kobe 59 59 59):\n");
scanf("%s", stusToModify);
int found = 0;
for (int i = 0; i < studentMember; i++) {
if (strcmp(studentInformation[i].stus, stusToModify) == 0) {
found = 1;
scanf("%d %s %lf %lf %lf",
&studentInformation[i].classes,
studentInformation[i].names,
&studentInformation[i].mathGrade,
&studentInformation[i].physicsGrade,
&studentInformation[i].englishGrade);
studentInformation[i].boolNew = 2;
printf("Student data modified successfully!\n");
break;
}
}
if (!found) {
printf("Student with number %s not found.\n", stusToModify);
}
}
}
void manage() {
printf(" 1.Input\n");
printf(" 2.Output\n");
printf(" 3.Order\n");
printf(" 4.Quit\n");
char keywords;
keywords = getchar();
switch (keywords) {
case 'i':
printf("Please input info of the three students\n");
inputStudentInformation(3);
break;
case 'o':
printf("You are trying to Output info\n");
break;
case 'm':
printf("You are trying to Make things ordered\n");
break;
case 'q':
printf("You are about to Quit\n");
break;
default:
printf("Wrong input\n");
break;
}
}
int main() {
char a[100];
manage();
modifyStudent();
printStudentOriginalScore();
return 0;
}

@ -1,323 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int studentMember = 7;
typedef struct storeInformation
{
char stus[100];
int classes;
char names[100];
double mathGrade;
double physicsGrade;
double englishGrade;
int boolNew;
} stu;
stu studentInformation[100] = {
{ "10001", 11, "Zhang", 99.5, 88.5, 89.5, 0 },
{ "10002", 12, "Yang", 77.9, 56.5, 87.5, 0 },
{ "10003", 11, "Liang", 92.5, 99.0, 60.0, 0 },
{ "10004", 11, "Cai", 89.6, 56.9, 90.5, 0 },
{ "10005", 14, "Fu", 55.6, 67.9, 98.9, 0 },
{ "10006", 12, "Mao", 22.1, 45.9, 99.2, 0 },
{ "10007", 13, "Zhan", 35.6, 67.9, 88.0, 0 }
};
void input(int i) {
printf("Id ");
scanf("%s", studentInformation[i].stus);
printf("class ");
scanf("%d", &studentInformation[i].classes);
printf("name ");
scanf("%s", studentInformation[i].names);
printf("score1 ");
scanf("%lf", &studentInformation[i].mathGrade);
printf("score2 ");
scanf("%lf", &studentInformation[i].physicsGrade);
printf("score3 ");
scanf("%lf", &studentInformation[i].englishGrade);
}
void inputStudentInformation() {
char a[10];
do {
input(studentMember);
studentInformation[studentMember].boolNew = 0;
studentMember++;
printf("One student has been input!\n");
printf("cotinue?(yes/no)\n");
scanf("%s", &a);
} while (strcmp(a, "no") == 0);
}
void insertedNew() {
int i = studentMember;
input(i);
studentMember++;
studentInformation[i].boolNew = 1;
printf("One student has been input!\n");
}
void informationClear(char a[100]) {
int i = 0;
for (i = 0; i < studentMember; i++) {
if (strcmp(a, studentInformation[i].stus) == 0 || strcmp(a, studentInformation[i].names) == 0) {
memset(&studentInformation[i], 0, sizeof(studentInformation[i]));
}
}
}
void sortStudents() {
for (int i = 0; i < studentMember - 1; i++) {
for (int j = 0; j < studentMember - i - 1; j++) {
double totalScoreJ = studentInformation[j].mathGrade + studentInformation[j].physicsGrade + studentInformation[j].englishGrade;
double totalScoreJ1 = studentInformation[j + 1].mathGrade + studentInformation[j + 1].physicsGrade + studentInformation[j + 1].englishGrade;
if (studentInformation[j].classes > studentInformation[j + 1].classes ||
(studentInformation[j].classes == studentInformation[j + 1].classes && totalScoreJ < totalScoreJ1)) {
stu temp = studentInformation[j];
studentInformation[j] = studentInformation[j + 1];
studentInformation[j + 1] = temp;
}
}
}
printf("Students have been sorted!\n");
}
void printStudentOriginalScore() {
int classs = 0;
for (int i = 0; i < studentMember; i++) {
if (studentInformation[i].classes != 0) {
if (studentInformation[i].classes != classs) {
printf("%d %s %s %.1f %.1f %.1f %s\n",
studentInformation[i].classes,
studentInformation[i].stus,
studentInformation[i].names,
studentInformation[i].mathGrade,
studentInformation[i].physicsGrade,
studentInformation[i].englishGrade,
studentInformation[i].boolNew == 0 ? "" : studentInformation[i].boolNew == 1 ? "inserted" : "modified");
}
else {
printf(" %s %s %.1f %.1f %.1f %s\n",
studentInformation[i].stus,
studentInformation[i].names,
studentInformation[i].mathGrade,
studentInformation[i].physicsGrade,
studentInformation[i].englishGrade,
studentInformation[i].boolNew == 0 ? "" : studentInformation[i].boolNew == 1 ? "inserted" : "modified");
}
classs = studentInformation[i].classes;
studentInformation[i].boolNew = 0;
}
}
}
void modifyStudent() {
char a[10];
printf("Are you sure(yes/no)");
scanf("%s", &a);
if ((strcmp(a, "yes")) == 0) {
char stusToModify[10];
printf("Enter the student number to modify, followed by new data ( 10001 2 Kobe 59 59 59):\n");
scanf("%s", stusToModify);
int found = 0;
for (int i = 0; i < studentMember; i++) {
if (strcmp(studentInformation[i].stus, stusToModify) == 0) {
found = 1;
scanf("%d %s %lf %lf %lf",
&studentInformation[i].classes,
studentInformation[i].names,
&studentInformation[i].mathGrade,
&studentInformation[i].physicsGrade,
&studentInformation[i].englishGrade);
studentInformation[i].boolNew = 2;
printf("Student data modified successfully!\n");
break;
}
}
if (!found) {
printf("Student with number %s not found.\n", stusToModify);
}
}
}
void queryByClassRange(int startClass, int endClass) {
printf("Students in classes %d to %d:\n", startClass, endClass);
for (int i = 0; i < studentMember; i++) {
if (studentInformation[i].classes >= startClass && studentInformation[i].classes <= endClass) {
printf("%s %d %s %.1f %.1f %.1f\n",
studentInformation[i].stus, studentInformation[i].classes, studentInformation[i].names,
studentInformation[i].mathGrade, studentInformation[i].physicsGrade, studentInformation[i].englishGrade);
}
}
}
void queryByIDRange(char startID[10], char endID[10]) {
printf("Students with IDs %s to %s:\n", startID, endID);
for (int i = 0; i < studentMember; i++) {
if (strcmp(studentInformation[i].stus, startID) >= 0 &&
strcmp(studentInformation[i].stus, endID) <= 0) {
printf("%s %d %s %.1f %.1f %.1f\n",
studentInformation[i].stus, studentInformation[i].classes, studentInformation[i].names,
studentInformation[i].mathGrade, studentInformation[i].physicsGrade, studentInformation[i].englishGrade);
}
}
}
void queryByNamePrefix(const char* prefix) {
printf("Students with names starting with %s:\n", prefix);
for (int i = 0; i < studentMember; i++) {
if (strncmp(studentInformation[i].names, prefix, strlen(prefix)) == 0) {
printf("%s %d %s %.1f %.1f %.1f\n",
studentInformation[i].stus, studentInformation[i].classes, studentInformation[i].names,
studentInformation[i].mathGrade, studentInformation[i].physicsGrade, studentInformation[i].englishGrade);
}
}
}
void queryByTotalScore(double threshold) {
printf("Students with total score >= %.1f:\n", threshold);
for (int i = 0; i < studentMember; i++) {
double totalScore = studentInformation[i].mathGrade + studentInformation[i].physicsGrade + studentInformation[i].englishGrade;
if (totalScore >= threshold) {
printf("%s %d %s %.1f %.1f %.1f\n",
studentInformation[i].stus, studentInformation[i].classes, studentInformation[i].names,
studentInformation[i].mathGrade, studentInformation[i].physicsGrade, studentInformation[i].englishGrade);
}
}
}
void queryByClassAndIDRange(int classNum, char startID[10], char endID[10]) {
printf("Students in class %d with IDs %s to %s:\n", classNum, startID, endID);
for (int i = 0; i < studentMember; i++) {
if (studentInformation[i].classes == classNum &&
strcmp(studentInformation[i].stus, startID) >= 0 &&
strcmp(studentInformation[i].stus, endID) <= 0) {
printf("%s %d %s %.1f %.1f %.1f\n",
studentInformation[i].stus, studentInformation[i].classes, studentInformation[i].names,
studentInformation[i].mathGrade, studentInformation[i].physicsGrade, studentInformation[i].englishGrade);
}
}
}
void queryByAttribute() {
char input[20];
printf("Enter search term (ID, class, or name): ");
scanf("%s", input);
printf("Search results for '%s':\n", input);
int found = 0;
for (int i = 0; i < studentMember; i++) {
if (strcmp(studentInformation[i].stus, input) == 0 ||
atoi(input) == studentInformation[i].classes ||
strcmp(studentInformation[i].names, input) == 0) {
printf("%s %d %s %.1f %.1f %.1f\n",
studentInformation[i].stus, studentInformation[i].classes, studentInformation[i].names,
studentInformation[i].mathGrade, studentInformation[i].physicsGrade, studentInformation[i].englishGrade);
found = 1;
}
}
if (!found) {
printf("No students found matching '%s'.\n", input);
}
}
void handleInput() {
int queryType;
printf("Enter query type (1-5): ");
scanf("%d", &queryType);
if (queryType == 1) {
int startClass, endClass;
printf("Enter class range (start end): ");
scanf("%d %d", &startClass, &endClass);
queryByClassRange(startClass, endClass);
}
else if (queryType == 2) {
char startID[10], endID[10];
printf("Enter ID range (start end): ");
scanf("%s %s", startID, endID);
queryByIDRange(startID, endID);
}
else if (queryType == 3) {
char prefix[10];
printf("Enter name prefix: ");
scanf("%s", prefix);
queryByNamePrefix(prefix);
}
else if (queryType == 4) {
double threshold;
printf("Enter total score threshold: ");
scanf("%lf", &threshold);
queryByTotalScore(threshold);
}
else if (queryType == 5) {
int classNum;
char startID[10], endID[10];
printf("Enter class and ID range (class startID endID): ");
scanf("%d %s %s", &classNum, startID, endID);
queryByClassAndIDRange(classNum, startID, endID);
}
else {
printf("Invalid query type.\n");
}
}
int manage() {
printf("1.input\n");
printf("2.delete\n");
printf("3.select\n");
printf("4.order\n");
printf("5.output\n");
printf("6.quit\n");
printf("Please input your option: ");
char keywords;
keywords = getchar();
while (keywords == '\n') {
keywords = getchar();
}
switch (keywords) {
case '1':
inputStudentInformation();
return 0;
case '2': {
char a[100], b[100];
do {
printf("Please enter student's ID or Name: ");
scanf("%s", a);
informationClear(a);
printf("Continue? (yes/no): ");
scanf("%s", b);
} while (strcmp(b, "no") != 0);
return 0;
}
case '3':
queryByAttribute();
return 0;
case '4':
sortStudents();
printStudentOriginalScore();
return 0;
case '5':
printStudentOriginalScore();
return 0;
case '6':
return 1;
default:
printf("Invalid option. Please try again.\n");
return 0;
}
}
int main() {
while (manage() == 0) {
}
return 0;
}

@ -1,190 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Node {
char stus[100];
int classes;
char names[100];
double mathGrade;
double physicsGrade;
double englishGrade;
int boolNew;
struct Node* next;
} Node;
Node* head = NULL;
Node* createNode() {
Node* newNode = (Node*)malloc(sizeof(Node));
newNode->next = NULL;
return newNode;
}
void input(Node* node) {
printf("Id ");
scanf("%s", node->stus);
printf("class ");
scanf("%d", &node->classes);
printf("name ");
scanf("%s", node->names);
printf("score1 ");
scanf("%lf", &node->mathGrade);
printf("score2 ");
scanf("%lf", &node->physicsGrade);
printf("score3 ");
scanf("%lf", &node->englishGrade);
node->boolNew = 0;
}
void inputStudentInformation() {
char a[10];
do {
Node* newNode = createNode();
input(newNode);
newNode->next = head;
head = newNode;
printf("One student has been input!\n");
printf("continue?(yes/no)\n");
scanf("%s", a);
} while (strcmp(a, "no") != 0);
}
void insertedNew() {
Node* newNode = createNode();
input(newNode);
newNode->boolNew = 1;
newNode->next = head;
head = newNode;
printf("One student has been input!\n");
}
void informationClear(char a[100]) {
Node** current = &head;
while (*current) {
Node* entry = *current;
if (strcmp(entry->stus, a) == 0 || strcmp(entry->names, a) == 0) {
*current = entry->next;
free(entry);
}
else {
current = &entry->next;
}
}
}
void sortStudents() {
Node* sorted = NULL;
Node* current = head;
while (current) {
Node* next = current->next;
if (!sorted || current->classes < sorted->classes ||
(current->classes == sorted->classes &&
current->mathGrade + current->physicsGrade + current->englishGrade >=
sorted->mathGrade + sorted->physicsGrade + sorted->englishGrade)) {
current->next = sorted;
sorted = current;
}
else {
Node* temp = sorted;
while (temp->next &&
(temp->next->classes < current->classes ||
(temp->next->classes == current->classes &&
temp->next->mathGrade + temp->next->physicsGrade + temp->next->englishGrade >=
current->mathGrade + current->physicsGrade + current->englishGrade))) {
temp = temp->next;
}
current->next = temp->next;
temp->next = current;
}
current = next;
}
head = sorted;
printf("Students have been sorted!\n");
}
void printStudentOriginalScore() {
Node* current = head;
int classs = 0;
while (current) {
if (current->classes != classs) {
printf("%d %s %s %.1f %.1f %.1f %s\n",
current->classes, current->stus, current->names,
current->mathGrade, current->physicsGrade, current->englishGrade,
current->boolNew == 0 ? "" : current->boolNew == 1 ? "inserted" : "modified");
}
else {
printf(" %s %s %.1f %.1f %.1f %s\n",
current->stus, current->names,
current->mathGrade, current->physicsGrade, current->englishGrade,
current->boolNew == 0 ? "" : current->boolNew == 1 ? "inserted" : "modified");
}
classs = current->classes;
current->boolNew = 0;
current = current->next;
}
}
void modifyStudent() {
char a[10];
printf("Are you sure(yes/no) ");
scanf("%s", a);
if (strcmp(a, "yes") == 0) {
char stusToModify[10];
printf("Enter the student number to modify, followed by new data ( 10001 2 Kobe 59 59 59):\n");
scanf("%s", stusToModify);
Node* current = head;
while (current) {
if (strcmp(current->stus, stusToModify) == 0) {
scanf("%d %s %lf %lf %lf",
&current->classes, current->names,
&current->mathGrade, &current->physicsGrade, &current->englishGrade);
current->boolNew = 2;
printf("Student data modified successfully!\n");
return;
}
current = current->next;
}
printf("Student with number %s not found.\n", stusToModify);
}
}
int manage() {
printf("1.input\n2.delete\n3.select\n4.order\n5.output\n6.quit\nPlease input your option: ");
char keywords;
scanf(" %c", &keywords);
switch (keywords) {
case '1':
inputStudentInformation();
return 0;
case '2': {
char a[100];
printf("Please enter student's ID or Name: ");
scanf("%s", a);
informationClear(a);
return 0;
}
case '3':
printStudentOriginalScore();
return 0;
case '4':
sortStudents();
printStudentOriginalScore();
return 0;
case '5':
printStudentOriginalScore();
return 0;
case '6':
return 1;
default:
printf("Invalid option. Please try again.\n");
return 0;
}
}
int main() {
while (manage() == 0) {
}
return 0;
}

42
test

@ -1,42 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int ans[11];
void f(char str[], int l0, int l) {
if (l0 == l) {
for (int i = 1; i <= ans[0]; i++) {
printf("%c", str[ans[i]]);
}
printf("\n");
return;
}
for (int i = 0; i < l0; i++) {
int flag = 1;
for (int j = 1; j <= ans[0]; j++) {
if (i == ans[j]) {
flag = 0;
break;
}
}
if (flag == 1) {
ans[++ans[0]] = i;
f(str, l0, l + 1);
ans[0]--;
}
}
}
void Cal(char* str)
{
int len = strlen(str);
for (int i = 0; i < len - 1; i++) {
for (int j = 0; j < len - 1 - i; j++) {
int tmp;
if (str[j] > str[j + 1]) {
tmp = str[j];
str[j] = str[j + 1];
str[j + 1] = tmp;
}
}
}
f(str, len, 0);
}
Loading…
Cancel
Save