1. 程式人生 > 其它 >如何使用工具類實現檔案上傳到指定目錄,並將相對地址儲存到資料庫中

如何使用工具類實現檔案上傳到指定目錄,並將相對地址儲存到資料庫中

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h> 
#define N 3        

typedef struct student {
    int id;             /*學生學號 */
    char name[20];         /*學生姓名 */
    char subject[20];     /*考試科目 */
    float perf;         /*平時成績 */
    float mid;             /*
期中成績 */ float final; /* 期末成績 */ float total; /* 總評成績 */ char level[10]; /* 成績等級 */ } STU; void input(STU[], int); /*輸入學生資訊 */ void calc(STU[], int); /*計算總評和等級 */ int fail(STU[], STU[], int); /*不及格學生統計 */ void sort(STU[], int); /*排序 */ void print(STU[], int
); /*輸出學生資訊*/ int main01() { STU st[N], fst[N]; // 陣列st記錄學生資訊,fst記錄不及格學生資訊 int k; // 用於記錄不及格學生個數 printf("錄入學生成績資訊:\n"); input(st, N); printf("\n成績處理...\n"); calc(st, N); k = fail(st, fst, N); sort(st, N); printf("\n學生成績排名情況:\n"); print(st, N); printf(
"\n不及格學生資訊:\n"); print(fst, k); return 0; } // 輸入學生資訊 void input(STU s[], int n) { int i; for (i = 0; i < n; i++) scanf("%d %s %s %f %f %f", &s[i].id, s[i].name, s[i].subject, &s[i].perf, &s[i].mid, &s[i].final); } // 計算總評和等級 void calc(STU s[], int n) { int i; for (i = 0; i < n; i++) { s[i].total = s[i].perf * 0.2 + s[i].mid * 0.2 + s[i].final * 0.6; if (s[i].total >= 90) strcpy(s[i].level, ""); else if (s[i].total >= 80) strcpy(s[i].level, ""); else if (s[i].total >= 70 ) strcpy(s[i].level, ""); else if (s[i].total >= 60 ) strcpy(s[i].level, "及格"); else strcpy(s[i].level, "不及格"); } } int fail(STU s[], STU t[], int n) { int i, k = 0; for (i = 0; i < n; i++) if (s[i].total < 60) t[k++] = s[i]; return k; } void sort(STU s[], int n) { int i, j; STU temp; for (i = 0; i < n - 1; i++) for (j = 0; j < n - 1 - i; j++) if (s[j].total < s[j + 1].total) { temp = s[j]; s[j] = s[j + 1]; s[j + 1] = temp; } } void print(STU s[], int n) { int i; printf("-----------------\n"); printf("學號 姓名 考試科目 平時成績 期中成績 期末成績 總評成績 成績等級\n"); for (i = 0; i < n; i++) printf("%5d %5s%10s %5.1f %5.1f %5.1f %5.1f %10s\n", s[i].id, s[i].name, s[i].subject, s[i].perf, s[i].mid, s[i].final, s[i].total, s[i].level); }

輸入資料時注意要不要加取地址符

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#define N 5

typedef struct stduent {
    long num;
    char name[20];
    int score;
}STU;
void input1(STU [], int );
int search_minst(STU[], STU[], int);
void output(STU[], int);
int main002() {
    STU stu[N], minst[N];
    int count;
    printf("輸入\n");
    input1(stu, N);

    printf("查詢\n");
    count = search_minst(stu, minst, N);

    printf("最低分有%d個,資訊如下:\n", count);
    output(minst, count);

    return 0;
 }

void input1(STU s[], int n) {
    int i ;
    for (i = 0; i < n; i++)
        scanf("%ld %s %d", &s[i].num, s[i].name, &s[i].score);    
}


void output(STU s[], int n) {
    int i;
    for (int i = 0; i < n; i++)
        printf("%ld  %s  %d\n", s[i].num, s[i].name, s[i].score);    
}

int search_minst(STU s[], STU min[], int n) {
    min[0] = s[0];
    for (int i = 0; i < n; i++)
        if (s[i].score < min[0].score)min[0] = s[i];

    int a = 1;
    for (int i = 0; i < n; i++)
        if (s[i].score == min[0].score && strcmp(s[i].name, min[0].name) != 0)
            min[a++] = s[i];
    return a;
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h> 
#include <string.h>
#define  N  5

// 定義結構體型別struct student,並定義其別名為STU 
typedef struct student {
    long int id;
    char name[20];
    float objective;    /*客觀題得分*/
    float subjective;    /*操作題得分*/
    float sum;
    char level[20];
}STU;

// 函式宣告
void input2(STU s[], int n);
void output2(STU s[], int n);
void process(STU s[], int n);

int main03() {
    STU stu[N];

    printf("錄入%d個考生資訊: 准考證號,姓名,客觀題得分(<=40),操作題得分(<=60)\n", N);
    input2(stu, N);

    printf("\n對考生資訊進行處理: 計算總分,確定等級\n");
    process(stu, N);

    printf("\n列印考生完整資訊: 准考證號,姓名,客觀題得分,操作題得分,總分,等級\n");
    output2(stu, N);

    return 0;
}

// 錄入考生資訊:准考證號,姓名,客觀題得分,操作題得分
void input2(STU s[], int n) {
    int i;
    for (i = 0; i < n; i++)
        scanf("%ld %s %f %f", &s[i].id, s[i].name, &s[i].objective,&s[i].subjective);
}

//輸出考生完整資訊: 准考證號,姓名,客觀題得分,操作題得分,總分,等級
void output2(STU s[], int n) {
    int i;
    for (i = 0; i < n; i++)
        printf("%10ld %10s %5.1f %5.1f %5.1f %10s\n", s[i].id, s[i].name, s[i].objective, s[i].subjective, s[i].sum, s[i].level);
}

// 對考生資訊進行處理:計算總分,排序,確定等級
void process(STU s[], int n) {
    STU temp;
    int i;
    for (int i = 0; i < n; i++)    
        s[i].sum =  s[i].objective +  s[i].subjective;

    for ( i = 0; i < n-1; i++)
        for (int j = 0; j < n-1-i; j++)
        {
            if (s[j].sum < s[j + 1].sum) {
                temp = s[j];
                s[j] = s[j + 1];
                s[j + 1] = temp;
            }
        }

    for ( i = 0; i < n; i++)
    {
        if (i < N * 0.1)strcpy(s[i].level, "good!");
        else if(i<=N*0.5&&i>0.1*N)strcpy(s[i].level, "qualified");
        else strcpy(s[i].level, "not qualified");
    }
    

}