rdhc1330's Profile
Reputation: 1
Apprentice
- Group:
- Active Members
- Active Posts:
- 130 (0.2 per day)
- Joined:
- 01-August 11
- Profile Views:
- 945
- Last Active:
Oct 23 2012 03:36 PM- Currently:
- Offline
Previous Fields
- Country:
- NZ
- OS Preference:
- Windows
- Favorite Browser:
- Chrome
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- PC
- Your Car:
- Who Cares
- Dream Kudos:
- 0
Latest Visitors
-
stevensonnz 
26 Sep 2012 - 16:39 -
jimblumberg 
06 Aug 2012 - 22:24 -
pohlod 
01 Aug 2012 - 20:36 -
inf3kted 
11 Apr 2012 - 01:20 -
hulla 
22 Sep 2011 - 04:35 -
Hezekiah 
22 Sep 2011 - 04:33 -
alias120 
21 Sep 2011 - 12:29 -
darek9576 
21 Sep 2011 - 03:32 -
supercorey 
16 Sep 2011 - 19:40 -
n8wxs 
14 Sep 2011 - 23:33
Posts I've Made
-
In Topic: problem with 3d rendering engine
Posted 23 Oct 2012
I get what you're saying I just don't quite understand how to execute this and where to put the thread.sleep()? If not in the constructor then where as it has to load in the code?
pbl, on 23 October 2012 - 06:59 PM, said:Does not make sense at all to actually execute updating code and Thread.sleep() in a constructor
You constructor will not exit until all this code is finish and constructor terminated
The constructor has to finish before the created object can be add() to a container -
In Topic: Problem: Not getting output
Posted 12 Aug 2012
That's great, thank you so much, was wondering how I was going to do that! You print all of the data in the function where I just want it to print only courses with no id numbers... how do I get it to do that? I have triedif(! id_num )
on the void print function? should look like this :S =Quote
"Courses with no students enrolled:
157112, System-Analysis, Credits 12, 0 students" -
In Topic: Problem: Not getting output
Posted 12 Aug 2012
Other txt file! -
In Topic: Question: How to read from a file and print only NO option.
Posted 7 Aug 2012
Sorry Jim! OK so that part of the code is working fine now... Here's the code in its entirety:
//--------------------------------------------------------------------------- #include <vcl.h> #include <tchar.h> #include <iostream> #include <fstream> #include <conio.h> using namespace std; const char STUDENT[] = "C:\\students.txt"; const char COURSES[] = "C:\\courses.txt"; class Student { public: Student(); Student(char firstName[] , char secondName[] , int id , char enrld); ~Student(); int getIDNumber(); char* getFirstName(); char* getSecondName(); char getEnrolled(); void setIDNumber( int id ); void setFirstName( char firstName[] ); void setSecondName( char secondName[] ); void setEnrolled( char enrolled ); void print(); private: char first_name[ 16 ]; char second_name[ 16 ]; int id_number; char enrolled; }; class Course { public: int course_identifier; char course_name[ 32 ]; int credits; int id_number; }; Student :: Student() { } Student :: ~Student() { } Student :: Student( char firstName[], char secondName[], int id, char enrld ) { strcpy( first_name , firstName ); strcpy(second_name , secondName ); id_number = id; enrolled = enrld; } int Student :: getIDNumber() { return id_number; } char Student :: getEnrolled() { return enrolled; } char* Student :: getFirstName() { return first_name; } char* Student :: getSecondName() { return second_name; } void Student :: setIDNumber( int id ) { id_number = id; } void Student :: setEnrolled( char enrolled ) { this -> enrolled = enrolled; } void Student :: setFirstName( char firstName[] ) { strcpy( first_name , firstName ); } void Student :: setSecondName( char secondName[] ) { strcpy( second_name , secondName ); } void Student :: print() { if( enrolled == 'N' ) { cout << " " << second_name << ", " << first_name << ": ID " << id_number << ", paid fees " << enrolled; } } bool readStudents( Student[] , int& ); void printAllStudents( Student[], int ); //--------------------------------------------------------------------------- int _tmain(int argc, _TCHAR* argv[]) { Student students[ 1024 ]; int nrOfStudents = 0; cout << "************************" << endl; cout << "* 159.234 Assignment 2 *" << endl; cout << "* 05155932 Syms C. *" << endl; cout << "* S2 2012 *" << endl; cout << "************************" << endl << endl; cout << "Students not enrolled in any paper: " << endl; if( !readStudents ( students , nrOfStudents ) ) return 1; printAllStudents( students , nrOfStudents ); getch(); return 0; } //--------------------------------------------------------------------------- bool readStudents( Student students[] , int &nrOfStudents) { ifstream read; read.open(STUDENT); if (! read.is_open()) { return false; } int nr = 0; char fName[16]; char sName[16]; char enrolled; int id; read >> nr; while (! read.eof() && nrOfStudents != nr) { read >> fName; read >> sName; read >> id; read >> enrolled; students[ nrOfStudents ] = Student( fName , sName , id , enrolled ); nrOfStudents++; } read.close(); return true; } //--------------------------------------------------------------------------- void printAllStudents( Student students[] , int nrOfStudents ) { for (int i = 0; i < nrOfStudents; i++) { students[i].print(); } } //---------------------------------------------------------------------------
The required output is supposed to be like:
Quote
Students not enrolled in any paper:
Blake, James: ID 7177323, paid fees N
It is doing this now after I changed the above piece of code to include the if statement.
Now I just need the code to read through the courses text file and read to print this:
Quote
Courses with no students enrolled: 157314, System-Analysis, credits 12, 0 students
I think I'm on the right track here, my code feels messy but it's the first time I've had a real go at classes so if there's anything else you could recommend then that would be fantastico. -
In Topic: Question: How to read from a file and print only NO option.
Posted 7 Aug 2012
[quote name='rdhc1330' date='07 August 2012 - 05:25 PM' timestamp='1344385550' post='1680461']
void Student :: print() { cout << "First Name: " << first_name << endl; cout << "Second Name: " << second_name << endl; cout << "ID: " << id_number << endl; cout << "Enrolled: " << enrolled << endl; cout << endl; }
Has been changed to:
void Student :: print() { if( enrolled == 'N' ) { cout << "\t" << second_name << ", " << first_name << ": ID " << id_number << ", paid fees " << enrolled; } cout << endl; }
My Information
- Member Title:
- D.I.C Head
- Age:
- 16 years old
- Birthday:
- June 26, 1996
- Gender:
-
- Location:
- New Zealand
- Full Name:
- Charles
- Years Programming:
- 1
- Programming Languages:
- C++, Ruby on Rails
Contact Information
- E-mail:
- Click here to e-mail me
Friends
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
hulla
22 Sep 2011 - 04:35hulla
21 Sep 2011 - 23:41