廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 2595 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
jianfengtw
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x3
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片
推文 x0
[C/C++] [請教]成績表分數的組距諸位大大你們會怎麼寫
功能如下
Exercise 4 : Please design a C++ program which allows user to enter the total students in class, student’s name, id and 3 scores, please do the followings:

1.Show Exercise No., Class, Name, and ID
2.Enter the total students, student’s name, id and 3 scores
3.Show all the student’s records
4.Show the distribution of each course
5.Ues new and delete operators to allocate memory dynamincally
Hints : struct Student{ // 定義一個結構資料型態Student
string id;
string name;
int score;
float average;
} ;
Student *rptr=new Student;
rptr.name=“Eric”;

Exercise 4
Class : x子xA Name : xxx ID : D9833045
How many students in class : 2
Name of student 1 : Eric
ID of student 1 : D9833007
Score 1 of student 1 : 89
Score 2 of student 1 : 56
Score 3 of student 1 : 74
Name of student 2 : Mary
ID of student 2 : D9833004
Score 1 of student 2 : 80
Score 2 of student 2 : 66
Score 3 of student 2 : 44
…………
Press any key to print class record

Name ID Score1 Score2 Score3 Average
Eric D9833007 89 56 74 73
Mary D9833004 80 66 44 63
…………
最主要顯示這個
Course 1 :
100~90 : 0
89~80 : 0
79~70 : 1
Name: Eric ID:D9833007 Score:73
69~60 : 1
Name: Mary ID:D9833004 Score:63
59~0 : 0 ………….

事實上我已經寫好了
但是寫的很長覺的自已寫的很豬頭
不知道有沒有比較簡短的寫法

不知道哪一位大大可以幫我解
Hints : struct Student{ // 定義一個結構資料型態Student
string id;
string name;
int score;
float average;
} ;
Student *rptr=new Student; <--還有這二段我看不太了解
rptr.name=“Eric”; <--不知道哪一位大大可以幫我
說明一下
為什麼可這樣做

這是我寫的程式

//

#include "stdafx.h"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
int i,j,n;
int max=0,min=0;
int total={0};
cout <<"Exercise 4"<<endl;
cout <<"Class : X子XA Name : XXX ID : DXXXXXXXXX " << endl;
cout <<"How many students in class:";
cin >> n;

struct person {char name;// 定義一個結構資料型態Student
..

訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容



[ 此文章被jianfengtw在2005-04-23 16:57重新編輯 ]



獻花 x0 回到頂端 [樓 主] From:台灣台灣索尼 | Posted:2005-04-23 01:41 |
kk889180
個人頭像
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x61
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

下面是引用jianfengtw於2005-04-23 01:41發表的 [請教]成績表分數的組距:

Student *rptr=new Student[100]; <--還有這二段我看不太了解
rptr[2].name=“Eric”;           <--不知道哪一位先生可以幫我說明一下
.......

宣告一陣列rptr為學生結構


[ 此文章被kk889180在2005-04-23 22:43重新編輯 ]


獻花 x0 回到頂端 [1 樓] From:台灣亞太線上 | Posted:2005-04-23 07:19 |
jianfengtw
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x3
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

謝謝k大的解答
了解了~~
但我想知道
比較組距的分法
個位大大會怎麼寫


獻花 x0 回到頂端 [2 樓] From:台灣台灣索尼 | Posted:2005-04-23 16:59 |
kk889180
個人頭像
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x61
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

哈哈你被我騙了
我前面的是錯的喔 表情
之前以為是要把三種分數分為cause 1,2,3討論(該打該打 表情 )
叫我popo就好了,因為我想努力po文章,後面加個大很奇怪,因為我算新手 表情

這應該算平凡的打法吧 表情
只是把你程式一個一個打的地方換成迴圈
複製程式
#include<stdio.h>
#include<conio.h>
#define swap(float x,float y) {int t;t=x;x=y;y=t;}
struct person
{
 char name[ 10 ];
 char id[ 10 ];
 int score[ 3 ];
 float average;
};

void main()
{
 FILE *fin,*fout;
 int i,l,j,num=5,n=0;
 person *student[ 5 ];
 for(l=0;l<num;l++)
 {
  scanf("%s %s",student[ l ].name,student[ l ].id);
  for(i=0;i<3;i++) 
  {
   scanf("%d",student[ l ].score[ i ]);
   student[ l ].average += student[ l ].score[ i ];
  }
  student[ l ].average /= 3;
 }
 for(i=0;i<n;i++) 
 { 
  for(j=i+1;j<n;j++) 
  { 
   if(student[ i ].average<student[ l ].average);
   {
    swap(student[ l ].average,student[ l ].average);
   }  
  } 
 }
 l=0;
 i=89;
 while(i>=0)
 {
  if(student[ l ].average>i) 
  {
   n++;
   l++;
  }
  else
  {
   if(i>58) 
   {
    if(i==89)printf("%d~%d = %d",i+11,i+1,n);
    else printf("%d~%d = %d",i+10,i+1,n);
   }   
   else
   {
    printf("Name : %s ID : %s",student[ l ].name,student[ l ].id);
    printf("%d~%d = %d",i+10,i+1,n);
   }
   i-=10;
   n=0;
  }
 }
}


[ 此文章被kk889180在2005-04-23 23:29重新編輯 ]


獻花 x0 回到頂端 [3 樓] From:台灣亞太線上 | Posted:2005-04-23 22:43 |

首頁  發表文章 發表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.025221 second(s),query:16 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言