问题描述
现在我正在开发Structures,所以在结构方面我遇到了很多错误。
目标:
=>定义5名学生的结构
=>姓名
=> id
=>定义出生日期的结构
=>那天
=>月份
=>年份
实际上主要是按ID,姓名,出生日期对数据进行排序。
我在数据功能和显示功能方面遇到问题.. !!
请帮助.. .. ..
Hi now I''m working on Structures, So being a nobe in Structure I''ve encountered a number of errors.
OBJECTIVE:
=> define a structure of 5 student
=> name
=> id
=> define a structure for date of birth
=> day
=> month
=> year
Actually the main thing is to sort the data by ID, Name, date Of Birth.
I''m facing problem in data function and display function .. !!
P L E A S E HELP .. .. .. .
// Records.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
struct date
{
int day, month, year;
};
struct student
{
char name[5][15];
int id[5];
};
void data(student s[], date d, int size)
{
for (int i = 0; i < size; i++)
{
cout << "Name Student # " << i+1 << ": ";
cin.get(s.name[i], 15+1); // Trouble Here .. !!!!?!?!?!?!?!?! What should I write this .. ????
cout << "I.D" << endl;
cout << setw(10) << "Day_Month_Year" << endl;
cin >> d.day >> d.month >> d.year;
}
}
void display(student s[], date d)
{
cout << "I N F O" << endl;
cout << setw(5) << "I.D" << s.id << endl
<< setw(5) << "NAME" << s.name << endl
<< setw(12) << "Date Of Birth" << endl
<< setw(12) << "Day >> Month >> Year" << endl
<< setw(4) << d.day << setw(4) << d.month << setw(4) << d.year
<< endl;
}
int main()
{
const int size = 5;
student s;
date d;
data(s, d);
display(s, d);
return 0;
}
[edit]仅限主题:删除SHOUTING - OriginalGriff [/ edit]
[edit]Subject only: SHOUTING removed - OriginalGriff[/edit]
推荐答案
struct MyDate
{
int day, month, year;
};
struct student
{
char name[15];
int id;
MyDate birthday;
};
student students[5];
// ...
我建议重命名''date''结构,因为你会在你的结构和一些同名的C / C ++之间混淆。
这有点像家庭作业,所以我留下你来确定剩下的细节......
I''d suggest renaming the ''date'' structure as I have here because you will get confused between your structure and some C/C++ things of the same name.
This somewhat looks like homework, so I leave you here to determine the remaining details...
这篇关于理解C ++结构的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!