Archive for 十月, 2010

29
十月

程式設計10/29上課:陣列及排序

   Posted by: admin    in 程式設計一(99)

20101029P

 

 

排序程式說明

排序程式說明

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

29
十月

程式設計10/29程式:陣列及排序

   Posted by: admin    in 程式設計一(99)

#include <stdio.h>
#include <stdlib.h>
//排序比較函數 
int compare( const void* arg1, const void* arg2 )
{
    float f1 = *((float*) arg1);
    float f2 = *((float*) arg2);
 
    if( F1 > F2)
       return -1
    else if( f1 < f2)
       return 1
    return 0;
}
int main(int argc, char *argv[])
{
    FILE *fin;
    int s1, s2;//各科分數的變數 
    float avg[100];//平均分數的變數 
    int i, num=0;
    int ret;//傳回值用來檢查檔案是否到底 
    fin = fopen("score.txt", "r");
    ret=fscanf(fin, "%d %d\n", &s1, &s2);  
    while (ret >0)
    {
        avg[num++] = ((float) (s1+s2))* 0.5;//算平均 
        ret=fscanf(fin, "%d %d\n", s1, s2)  
    }   
    fclose(fin);
    qsort(avg, num, sizeof(float), compare)
    for (i=0; i< num; i++)
       printf( "%5.1f\n", avg[i]);  
    return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

20101026M

音訊的原理介紹

音訊的原理介紹

多媒體光碟製作

多媒體光碟製作

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

20101025D

使用WindowsForm橾作學生資料庫

使用WindowsForm橾作學生資料庫

透過dataset及dataGridView呈現資料

透過dataset及dataGridView呈現資料

呈現學生資料的簡單Windows Form

呈現學生資料的簡單Windows Form

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

string SID = null;
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
    string NewID = dataGridView1.CurrentRow.Cells[0].Value.ToString();
    if (NewID == SID) return;
    SID = NewID;
    Student student = ReadStudent(SID);
    textBox1.Text = student.SID;
    textBox2.Text = student.SName;
    textBox3.Text = student.Math.ToString();
    textBox4.Text = student.Lang.ToString();
 
}
Student ReadStudent(string sID)
{
    string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\\Documents an" +
        "d Settings\\htchu\\My Documents\\db1.mdb";
    System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString);
 
    string queryString = "SELECT [Student].[SNAME], [Student].[MATH], [Student].[LANG] FROM [Student] WHERE" +
        " ([Student].[SID] = @SID)";
    System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand();
    dbCommand.CommandText = queryString;
    dbCommand.Connection = dbConnection;
 
    System.Data.IDataParameter dbParam_sID = new System.Data.OleDb.OleDbParameter();
    dbParam_sID.ParameterName = "@SID";
    dbParam_sID.Value = sID;
    dbParam_sID.DbType = System.Data.DbType.String;
    dbCommand.Parameters.Add(dbParam_sID);
 
    dbConnection.Open();
    System.Data.IDataReader dataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
    dataReader.Read();
 
    Student student = new Student();
    student.SID = sID;
    student.SName = dataReader.GetString(0);
    student.Math = dataReader.GetInt32(1);
    student.Lang = dataReader.GetInt32(2);
 
    dbConnection.Close();
    return student;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,