Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 .. .. .. .


C++
// 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]Subject only: SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 31-Mar-13 0:51am
v2
Comments
David Serrano Martínez 31-Mar-13 7:39am    
Are you sure your objective is properly stated? You should link a date of birth for each one of your students. So definitely creating a structure for holding your five students and another structure for holding a unique date of birth is a bizarre design to me.

You will also find multiple compilation errors. For instance, data() needs three arguments, not two. You are passing values to data() by value, not by reference and, inside data, you can set only one date of birth (????).

Please, reconsider what is exactly what you are trying to achieve with your code.
Captain Price 31-Mar-13 8:03am    
Your question is not clear to me ! How do you want to sort and what to sort ?

1 solution

For each student, I think you want to put their birthdate in the structure. Try this:

C++
struct MyDate
{
    int day, month, year;
};

struct student
{
    char name[15];
    int id;
    MyDate birthday;
};

student students[5];

//  ...


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...
 
Share this answer
 
v3
Comments
Usman Hunjra 1-Apr-13 11:30am    
hmm thank you ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900