[QUOTE=mechanarchy;38643016]The thing about cities is they basically are 2D - once you've got the floor level they rarely change as they go up, their cross-section stays the same.
I haven't generated any cities myself, so I can't really help you much. [url=https://dl.dropbox.com/u/6929441/screenshots/citygen.gif]This animation[/url] ([url=https://dl.dropbox.com/u/6929441/screenshots/citygen-1.png]end result[/url], [url=https://dl.dropbox.com/u/6929441/screenshots/citygen-2.png]3d render[/url]) was posted in one of the WAYWO threads a few iterations back, so maybe it will give you a pointer in the right direction[/QUOTE]
That definitely does help, thank you.
How are those roads generated though? Recursively?
Can someone that uses glfw and glew answer me if this linking sequence is correct?
I am just incuding the glew.h and glew.c in my program directly
[lua]-- A solution contains projects, and defines the available configurations
solution "TheWorld"
configurations { "Debug", "Release" }
location "build"
-- A project defines one build target
project "TheWorld"
location "build"
kind "ConsoleApp" -- Console Window
language "C++"
files { "./src/**.cpp","./src/**.c","./src/**.hpp", "./src/**.h","../externSRC/**.cpp","../externSRC/**.c","../externSRC/**.hpp", "../externSRC/**.h" }
excludes { "../externSRC/SOIL/original/*" }
libdirs { "../lib/" }
includedirs { "../include/"}
configuration "Debug"
defines { "DEBUG" , "GLEW_STATIC", "GLFW_DLL"}
flags { "Symbols" }
links {"glfwdll", "glu32", "opengl32"}
targetname ("TheWorldd")
targetdir "./bin/Debug"
configuration "Release"
--debugdir ("./")
defines { "NDEBUG", "GLEW_STATIC", "GLFW_DLL" }
flags { "OptimizeSpeed" }
links { "glfwdll", "glu32", "opengl32" }
targetdir "./bin/Release"
[/lua]
[QUOTE=chaoselite;38646279]That definitely does help, thank you.
How are those roads generated though? Recursively?[/QUOTE]
Iteratively I think.
You can see the first road just roughly bisects the image and nodes are spaced roughly evenly along it. then from the nodes you just draw a line out in some direction and add more nodes every so often. Eventually you'd join the nodes up or merge really close ones together (as I think happens in the animation at some point).
That's the basic idea of it - once you get something more or less working you can of course fiddle with the parameters to get 'roads' of a certain width or buildings of at least xyz size, etc.
Can someone link me to a good xCode tutorial? All of the ones I'm finding have a part 1, but nothing after that.
Does anyone have any tools or ideas as to why opengl wouldnt be drawing?
[editline]30th November 2012[/editline]
Can someone check over this and make sure that the matrices are correct?
[cpp]
Program::Program()
{
mPosition = glm::vec3( 0, 0, 5 );
mHorizontalAngle = 3.14f;
mVerticalAngle = 0.0f;
mFoV = 75.0f;
mOrtho = glm::ortho( 0.f, (float)Settings::Running.GetWidth(), (float)Settings::Running.GetHeight(), 0.f, -5.f, 5.f );
}
Program::~Program()
{
//dtor
}
void Program::HandleEvents()
{
}
void Program::Update()
{
float speed = 1.0f;
float mouseSpeed = 0.005f;
float deltaTime = ( Game::GetGame()->GetDelta()) * 0.01f;
mHorizontalAngle -= mouseSpeed * deltaTime * ( Game::GetGame()->GetMouseDelta().x );
mVerticalAngle -= mouseSpeed * deltaTime * ( Game::GetGame()->GetMouseDelta().y );
glm::vec3 direction(
cos(mVerticalAngle) * sin(mHorizontalAngle),
sin(mVerticalAngle),
cos(mVerticalAngle) * cos(mHorizontalAngle)
);
glm::vec3 right = glm::vec3(
sin(mHorizontalAngle - 3.14f/2.0f),
0,
cos(mHorizontalAngle - 3.14f/2.0f)
);
glm::vec3 up = glm::cross( right, direction );
if (glfwGetKey('W'))
{
mPosition += direction * deltaTime * speed;
}
if (glfwGetKey('S'))
{
mPosition -= direction * deltaTime * speed;
}
if (glfwGetKey('D'))
{
mPosition += right * deltaTime * speed;
}
if (glfwGetKey('A'))
{
mPosition -= right * deltaTime * speed;
}
glm::mat4 ProjectionMatrix = glm::perspective(mFoV, 4.0f / 3.0f, 0.1f, 250.0f);
glm::mat4 ViewMatrix = glm::lookAt( mPosition, mPosition + direction, up );
ProjView = ProjectionMatrix * ViewMatrix;
}
void Program::Draw()
{
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
}
[/cpp]
mOrtho = glm::ortho( 0.f, (float)Settings::Running.GetWidth(), (float)Settings::Running.GetHeight(), 0.f, -5.f, 5.f );
shouldn't that be:
mOrtho = glm::ortho( 0.f, (float)Settings::Running.GetWidth(), 0.f, (float)Settings::Running.GetHeight(), -5.f, 5.f );
?
(I'm using openTK, so it might be different for you..)
[QUOTE=Felheart;38658132]mOrtho = glm::ortho( 0.f, (float)Settings::Running.GetWidth(), (float)Settings::Running.GetHeight(), 0.f, -5.f, 5.f );
shouldn't that be:
mOrtho = glm::ortho( 0.f, (float)Settings::Running.GetWidth(), 0.f, (float)Settings::Running.GetHeight(), -5.f, 5.f );
?
(I'm using openTK, so it might be different for you..)[/QUOTE]
glm::ortho is defined as
[cpp]
glm::mat4 glm::ortho(
float left, float right,
float bottom, float top,
float zNear, float zFar);
[/cpp]
and I want the top left to be 0,0
Ok should be correct then.
Do you clear color depth AND stencil ?
Do you clear with a correct alpha?
Try to change the clear color first and see if it clears the sceen correctly in the first place.
Disable ArrayBuffer and Texture2D and see if you can draw with just colors.
Draw a colored triangle in immediate mode and see if its working...
If you're sure it's the transformations load a Identity everywhere and only set the target coordinates in the vertexbuffer directly.
And also check for NaN values in your position & direction after a few frames!!
Really, [B]REALLY[/B] stupid question, but how would I change the color of my text to #FF9900? (Orange, basically.)
I have no experience with HTML, I just want a title.
<font color=#ff9900>your text</font>
if I want to multiply my projection and view matricies and then in the object update multiply this by the model would this be the correct order?
[cpp]
glm::mat4 ProjectionMatrix = glm::perspective(mFoV, 4.0f / 3.0f, 0.1f, 250.0f);
glm::mat4 ViewMatrix = glm::lookAt( mPosition, mPosition + direction, up );
ProjView = ProjectionMatrix * ViewMatrix
//In obj update
MVP = ProjView * modelMatrix;[/cpp]
I know the correct order is
[cpp]MVP= ProjectionMatrix * ViewMatrix * glm::mat4(1.0f);[/cpp]
[QUOTE=Richy19;38665776]if I want to multiply my projection and view matricies and then in the object update multiply this by the model would this be the correct order?
[cpp]
glm::mat4 ProjectionMatrix = glm::perspective(mFoV, 4.0f / 3.0f, 0.1f, 250.0f);
glm::mat4 ViewMatrix = glm::lookAt( mPosition, mPosition + direction, up );
ProjView = ProjectionMatrix * ViewMatrix
//In obj update
MVP = ProjView * modelMatrix;[/cpp]
I know the correct order is
[cpp]MVP= ProjectionMatrix * ViewMatrix * glm::mat4(1.0f);[/cpp][/QUOTE]
Yes, that's correct. However, why are you multiplying by the identity matrix in your last snippet?
[QUOTE=ArgvCompany;38665832]Yes, that's correct. However, why are you multiplying by the identity matrix in your last snippet?[/QUOTE]
That would be the model matrix (not doing anything wit it at the moment)
Hi guys.
I'm an EEE student and I'm currently working in C.
So basically, I have an assignment to make involving doing a chess game in C.
So far so good, since there are lots of chess games already made on the web. The thing is, I'm not too good with Files and our game is going to feature loading and saving our game.
In this case, our professor wants us to startup our game from a .txt file called "StartGame" that has the following in it:
[code]
a;2;1;100;w/
b;2;1;100;w/
c;2;1;100;w/
d;2;1;100;w/
e;2;1;100;w/
f;2;1;100;w/
g;2;1;100;w/
h;2;1;100;w/
a;7;1;100;b/
b;7;1;100;b/
c;7;1;100;b/
d;7;1;100;b/
e;7;1;100;b/
f;7;1;100;b/
g;7;1;100;b/
h;7;1;100;b/
a;8;1;500;b/
h;8;1;500;b/
a;1;1;500;w/
h;1;1;500;w/
b;8;1;300;b/
g;8;1;300;b/
b;1;1;300;w/
g;1;1;300;w/
c;8;1;305;b/
f;8;1;305;b/
c;1;1;305;w/
f;1;1;305;w/
d;8;1;900;b/
d;1;1;900;w/
e;8;1;2000;b/
e;1;1;2000;w/
w
[/code]
Which is the positions of the pieces on the board.
Ok, now I also have to save my game during the in-game menu to an existing .txt file given to us by the professors containing a previously saved game to use as a template. When I save my game, I want to overwrite what's in it. Here's the file content:
[code]
a;2;1;100;w/
b;2;0;100;w/
c;2;0;100;w/
d;2;0;100;w/
e;2;0;100;w/
f;2;1;100;w/
g;2;0;100;w/
h;2;0;100;w/
a;7;0;100;b/
b;7;0;100;b/
c;7;0;100;b/
d;7;0;100;b/
e;7;0;100;b/
f;7;1;100;b/
g;7;0;100;b/
h;7;0;100;b/
a;8;0;500;b/
h;8;1;500;b/
a;5;1;500;w/
h;1;0;500;w/
b;8;1;300;b/
g;8;0;300;b/
a;3;1;300;w/
g;1;0;300;w/
c;8;1;305;b/
f;8;0;305;b/
c;1;1;305;w/
f;1;0;305;w/
f;3;1;900;b/
d;1;1;900;w/
e;8;1;2000;b/
e;1;1;2000;w/
w
[/code]
So, for starters we have to save our piece information in data structures and work from there. My professors even gave me this function called "showboard" that shows the board content from the data structures:
[code]
void showBoard(PIECE pieces[32]){
char piece;
int i, j;
int board[MAXLINES][MAXCOL] = {-1, 1, 2, 3, 4, 5, 6, 7, 8, -1,
16, 0, 0,0, 0, 0, 0, 0, 0, 16,
15, 0, 0, 0, 0, 0, 0, 0, 0, 15,
14, 0, 0, 0, 0, 0, 0, 0, 0, 14,
13, 0, 0, 0, 0, 0, 0, 0, 0, 13,
12, 0, 0, 0, 0, 0, 0, 0, 0, 12,
11, 0, 0, 0, 0, 0, 0, 0, 0, 11,
10, 0, 0, 0, 0, 0, 0, 0, 0, 10,
9, 0, 0, 0, 0, 0, 0, 0, 0, 9,
-1, 1, 2, 3, 4, 5, 6, 7, 8, -1
};
int pieceIndex = 0;
int pieceSquare[2];
for (pieceIndex = 0; pieceIndex < 32; pieceIndex++){
if(pieces[pieceIndex].state==1){
pieceSquare[0] = pieces[pieceIndex].square.file - 'a' + 1;
pieceSquare[1] = '8' - pieces[pieceIndex].square.rank + 1;
board[ pieceSquare[1] ][ pieceSquare[0] ] = ( pieces[pieceIndex].color == 'w' ? pieces[pieceIndex].type : -pieces[pieceIndex].type) ;
}
}
for (i = 0; i < MAXLINES; i++) {
printf("\n");
for (j = 0; j < MAXCOL; j++) {
switch (board[i][j]) {
case -1:
piece = ' ';
break;
case 0:
piece = ' ';
break;
case 1:
piece = 'a';
break;
case 2:
piece = 'b';
break;
case 3:
piece = 'c';
break;
case 4:
piece = 'd';
break;
case 5:
piece = 'e';
break;
case 6:
piece = 'f';
break;
case 7:
piece = 'g';
break;
case 8:
piece = 'h';
break;
case 9:
piece = '1';
break;
case 10:
piece = '2';
break;
case 11:
piece = '3';
break;
case 12:
piece = '4';
break;
case 13:
piece = '5';
break;
case 14:
piece = '6';
break;
case 15:
piece = '7';
break;
case 16:
piece = '8';
break;
case 100:
piece = 'P';
break;
case 300:
piece = 'N';
break;
case 305:
piece = 'B';
break;
case 500:
piece = 'R';
break;
case 900:
piece = 'Q';
break;
case 2000:
piece = 'K';
break;
case -100:
piece = 'p';
break;
case -300:
piece = 'n';
break;
case -305:
piece = 'b';
break;
case -500:
piece = 'r';
break;
case -900:
piece = 'q';
break;
case -2000:
piece = 'k';
break;
}
if ((i != 0 && j != 0) && (i != MAXLINES - 1 && j != MAXCOL - 1)) {
if (((j % 2 != 0 && i % 2 != 0) || (i % 2 == 0 && j % 2 == 0)))
printf("%c[%d;%dm %c %c[%dm", 27, (piece<'a')?36:35, 47, piece, 27, 0); //white
else
printf("%c[%d;%dm %c %c[%dm", 27, (piece<'a')?36:35, 40, piece, 27, 0); //black
} else printf("%c[%d;%dm %c %c[%dm", 27, 37, 44, piece, 27, 0); // white
}
}
printf("\n\n");
}
[/code]
So, I'm still in a very early stage of the program and so far I've only done this:
[code]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int pawn = 100;
const int horse = 300;
const int bishop = 305;
const int tower = 500;
const int queen = 900;
const int king = 2000;
const startup[8][8] = { tower, horse, bishop, queen, king, bishop, horse, tower, pawn, pawn, pawn, pawn, pawn, pawn, pawn, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -pawn, -pawn, -pawn, -pawn, -pawn, -pawn, -pawn, -tower, -horse, -bishop, -queen, -king, -bishop, -horse, -tower};
int board [8][8];
typedef struct piece
{
int state;
int type;
char color; // w for white b for black
SQUARE square;
} PIECE;
typedef struct square
{
char file // a to h
char rank // 1 to 8
} SQUARE;
void main_menu ()
{
printf("\t\t*****JOGO DE XADREZ******\n\n");
printf("1 - Novo Jogo\n"); //New game
printf("2 - Continuar Jogo\n"); // Resume game
printf("\n3 - Sair do Jogo\n"); // Exit game
}
[/code]
where should I go from here? I mean, I've never done anything of the sort.
And how am I suppose to write on file for the game save?
My view is slightly moving to the left, like if the mouse was slightly being moved to the left.
I dont know if this is a precision thing or what but this is my code if anyone can see anything wrong:
[cpp]
float deltaTime = ((int) (Game::GetGame()->GetDelta())) * 0.01;
float mouseSpeed = 0.01;
mHorizontalAngle -= mouseSpeed * deltaTime * ((int)( Game::GetGame()->GetMouseDelta().x) );
mVerticalAngle -= mouseSpeed * deltaTime * ((int)( Game::GetGame()->GetMouseDelta().y) );
glm::vec3 direction(
cos(mVerticalAngle) * sin(mHorizontalAngle),
sin(mVerticalAngle),
cos(mVerticalAngle) * cos(mHorizontalAngle)
);
if (glfwGetKey('W'))
{
mPosition += glm::vec3(0, 0, -1) * deltaTime;
}
if (glfwGetKey('S'))
{
mPosition -= glm::vec3(0, 0, -1) * deltaTime;
}
if (glfwGetKey('D'))
{
mPosition += glm::vec3(1, 0, 0) * deltaTime;
}
if (glfwGetKey('A'))
{
mPosition -= glm::vec3(1, 0, 0) * deltaTime;
}
glm::mat4 ProjectionMatrix = glm::perspective(mFoV, 4.0f / 3.0f, 0.1f, 250.0f);
glm::mat4 ViewMatrix = glm::lookAt( mPosition, mPosition + direction, glm::vec3(0,1,0) );
ProjView = ProjectionMatrix * ViewMatrix * glm::mat4(1.0f);
[/cpp]
All external variables are defined here:
[cpp]
glm::vec3 mPosition;
float mHorizontalAngle;
float mVerticalAngle;
float mFoV;
glm::mat4 ProjView;
glm::mat4 mOrtho;
/////
const GLuint GetDelta();
const glm::vec2 &GetMousePosition();
const glm::vec2 &GetMouseDelta();
[/cpp]
[editline]1st December 2012[/editline]
Seems to have fixed its self
[editline]1st December 2012[/editline]
Aaaand its back again
What's the best way to traverse a linked list in c++
If the linked list is your own implementation then this is probably the way to do it:
[cpp]Node *n = list.first; // point n to the first node in the linked list
while (n) { // loop until node is null
// do something with the node
n = n.next; // point n to the next node in the list
}[/cpp]
If you are talking about list in the STL, then use the iterators or ranged based for loop.
Because of how I do the view matrix and mouse stuff I am having a problem when my mouse reaches the bottom of the imaginary sphere of where its looking at.
[cpp]
mHorizontalAngle -= mouseSpeed * deltaTime * ( Game::GetGame()->GetMouseDelta().x );
mVerticalAngle -= mouseSpeed * deltaTime * ( Game::GetGame()->GetMouseDelta().y );
glm::vec3 direction(
cos(mVerticalAngle) * sin(mHorizontalAngle),
sin(mVerticalAngle),
cos(mVerticalAngle) * cos(mHorizontalAngle)
);
glm::mat4 ViewMatrix = glm::lookAt( mPosition, mPosition + direction, glm::vec3(0,1,0) );
[/cpp]
Meaning if I look at a triangle on the floor, I move the mouse/camera down and once it goes past the south pole of the sphere the triangle flips
Any of you guys have experience with libgdx? I've been looking around for a good library and it seems like this one has an active community
[QUOTE=Richy19;38666977]Because of how I do the view matrix and mouse stuff I am having a problem when my mouse reaches the bottom of the imaginary sphere of where its looking at.
[cpp]
mHorizontalAngle -= mouseSpeed * deltaTime * ( Game::GetGame()->GetMouseDelta().x );
mVerticalAngle -= mouseSpeed * deltaTime * ( Game::GetGame()->GetMouseDelta().y );
glm::vec3 direction(
cos(mVerticalAngle) * sin(mHorizontalAngle),
sin(mVerticalAngle),
cos(mVerticalAngle) * cos(mHorizontalAngle)
);
glm::mat4 ViewMatrix = glm::lookAt( mPosition, mPosition + direction, glm::vec3(0,1,0) );
[/cpp]
Meaning if I look at a triangle on the floor, I move the mouse/camera down and once it goes past the south pole of the sphere the triangle flips[/QUOTE]
I compare the Y angle against +/- pi/2 and clamp it to that limit.
Sorry for the inconvenience, but if anyone would be willing to download [URL="http://www.4shared.com/get/aGdTGsU6/OpenGL.html;jsessionid=74E93E6FB162D31B210926283F6A442B.dc322"]t[/URL]his file and tell me what comes up, that would be great... I've debugged my program to shit, did what everyone told me to, and it's still just displaying a white background.
[URL]http://www.mediafire.com/?7gca7qc24n8oibg[/URL]
[QUOTE=ECrownofFire;38667726]I compare the Y angle against +/- pi/2 and clamp it to that limit.[/QUOTE]
That did the trick, except Pi/2 must have been just over the allowed value before it flips
So I just times it by 0.99999 to make it slightly smaller
[cpp]
double Pim1 = Maths::dPIo2 * 0.99999;
mVerticalAngle = glm::clamp(mVerticalAngle, -Pim1, Pim1);[/cpp]
I'm writing my first makefile and having a hell of a time.
If anyone can help me out that would be awesome
[url]http://stackoverflow.com/questions/13665425/pattern-matching-mingw-make[/url]
Hey, how do you enable XNA 4 DirectX 9 debug out?? Thanks!
so were learning about linked lists, and this is the first assignment on the subject
god damn look at all this shit i dont even know where to start
the program is supposed to read 20 student names and grade numbers from a text file, and then through the usage of linked lists assign each name a letter grade too and display the name (first and last), their grade letter, and their number grade
my teacher left a bunch of instructions inside the code as to what to do
[cpp]//* This program displays a grade report based upon data read from
//* a text file and saved in a simple unordered linked list. Some file error
//* checking is included.
//*************************
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct tStudent
{
//node data
string studentFName;
string studentLName;
int testScore;
char grade;
//node link
tStudent* link;
};
void appendNode(tStudent*&, tStudent);
//add one node to end of linked list
//PREC: P1-starting address of list (NULL if empty list)
// P2-student record to added
//PSTC: student record added to end of list; P1 valid list start address
void calculateGrade(tStudent*);
//traverse unordered linked list and assign letter grade to each node based upon testScore
//PREC: P1-valid list starting address
//PSTC: student record nodes populated with letter grade
tStudent* findLastNode(tStudent*);
//traverse unordered linked list and return address of last node
//PREC: P1-valid list starting address
//PSTC: valid address of last node
bool getData(tStudent*&, int&);
//reads text file and builds unordered linked list of student records
//PREC: P1-starting address of list (NULL if empty list)
// P2-address of record count variable
//PSTC: P1-valid list starting address
// P2-record count of text file records
// returns true is successfull file access
void printResult(tStudent*);
//traverse unordered linked list and print formatted report
//PREC: P1-valid list starting address
//PSTC: student formatted report completed
int main()
{
int numStudents; //count of student records in text file
tStudent* pStudents = NULL; //head of linked list of student nodes
bool flag; //true indicates no file errors
flag = getData(pStudents, numStudents);
if (flag)
{
cout << "...Number of Student Records = " << numStudents << endl;
calculateGrade(pStudents);
printResult(pStudents);
}
else
cout << "...RUN TERMINATED\n";
system("pause");
return 0;
}
bool getData(tStudent*& pHead, int& listSize)
{
ifstream fStudents;
tStudent studentRec;
bool fileFound;
int i;
fStudents.open("StudentGrades.txt");
if(!fStudents)
{
fileFound = false;
cout << "\n*****FILE NOT FOUND*****\n";
}
else
{
fileFound = true;
i = 0;
fStudents >> studentRec.studentFName //initialize fStudents
>> studentRec.studentLName //...and load data
>> studentRec.testScore;
while(fStudents) //test fStudents for EOF
{
i++;
appendNode(pHead, studentRec); //add student node to end of list
fStudents >> studentRec.studentFName //modify fStudents
>> studentRec.studentLName //...and load data
>> studentRec.testScore;
}
listSize = i;
fStudents.close();
}
return fileFound;
}
void appendNode(tStudent*& pHead, tStudent student)
{
tStudent* pLastNode;
tStudent* pNewNode;
if(pHead != NULL)
{ // ***processing for all other nodes
// pLastNode = findLastNode(pHead);
// other statements to get a node from the heap
// and populate the data fields and link field;
// add node to the list
}
else
{ // ***processing for first node of list
// statements to get a node from the heap
// and populate data fields and link field;
// this is first node in list
}
}
tStudent* findLastNode(tStudent* pHead)
{
tStudent* pCurrent = pHead;
tStudent* pLastNode = NULL;
//traverse list and find address of last node
return pLastNode;
}
void calculateGrade(tStudent* pHead)
{
tStudent* pCurrent = pHead;
// traverse list and process each node to determine letter grade assigned
Node *n = list.first; // point n to the first node in the linked list
while (n) { // loop until node is null
// do something with the node
n = n.next; // point n to the next node in the list
}
}
void printResult(tStudent* pHead) //traverses L-list and prints data component
{
tStudent* pCurrent = pHead;
//Heading Line
cout << endl;
cout << left
<< setw(25) << "Student Name"
<< right
<< setw(10) << "Test Score"
<< setw(7) << "Grade" << endl << endl;
// Detail Lines - traverse list and print each node
cout << endl;
} [/cpp]
Trust me, I'm sure this is as basic as it gets, but I really need help with some simple C programming.
I have a text file with like 5 scores in it named "input.txt" and they're all on new lines. Two of the scores are above "90" and the others are below "90".
I need the program to both count the amount of scores over "90" and output them to a file called "output.txt".
We're using simple "if" and "while" loops, and file pointers, but that's what trips me up is understanding how to read and write to files. Please, help!
Make an array of the values in input.txt using fstream ([URL]http://www.bgsu.edu/departments/compsci/docs/read.html[/URL]), loop through the array, take out the values above 90, and put them into a new file.
Nevermind, figured it out.
[QUOTE=meppers;38677315]so were learning about linked lists, and this is the first assignment on the subject
god damn look at all this shit i dont even know where to start
the program is supposed to read 20 student names and grade numbers from a text file, and then through the usage of linked lists assign each name a letter grade too and display the name (first and last), their grade letter, and their number grade
my teacher left a bunch of instructions inside the code as to what to do
[cpp]old code[/cpp][/QUOTE]
ok so i got some good help from elsewhere and i have the program written up, i just need some help debugging it.
first here' the code (dont worry most of this was given to me, i'll show you what i did below)
[cpp]
//* This program displays a grade report based upon data read from
//* a text file and saved in a simple unordered linked list. Some file error
//* checking is included.
//*************************
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct tStudent
{
//node data
string studentFName;
string studentLName;
int testScore;
char grade;
//node link
tStudent* link;
};
void appendNode(tStudent*&, tStudent);
//add one node to end of linked list
//PREC: P1-starting address of list (NULL if empty list)
// P2-student record to added
//PSTC: student record added to end of list; P1 valid list start address
void calculateGrade(tStudent*);
//traverse unordered linked list and assign letter grade to each node based upon testScore
//PREC: P1-valid list starting address
//PSTC: student record nodes populated with letter grade
tStudent* findLastNode(tStudent*);
//traverse unordered linked list and return address of last node
//PREC: P1-valid list starting address
//PSTC: valid address of last node
bool getData(tStudent*&, int&);
//reads text file and builds unordered linked list of student records
//PREC: P1-starting address of list (NULL if empty list)
// P2-address of record count variable
//PSTC: P1-valid list starting address
// P2-record count of text file records
// returns true is successfull file access
void printResult(tStudent*);
//traverse unordered linked list and print formatted report
//PREC: P1-valid list starting address
//PSTC: student formatted report completed
int main()
{
int numStudents; //count of student records in text file
tStudent* pStudents = NULL; //head of linked list of student nodes
bool flag; //true indicates no file errors
flag = getData(pStudents, numStudents);
if (flag)
{
cout << "...Number of Student Records = " << numStudents << endl;
calculateGrade(pStudents);
printResult(pStudents);
}
else
cout << "...RUN TERMINATED\n";
system("pause");
return 0;
}
bool getData(tStudent*& pHead, int& listSize)
{
ifstream fStudents;
tStudent studentRec;
bool fileFound;
int i;
fStudents.open("StudentGrades.txt");
if(!fStudents)
{
fileFound = false;
cout << "\n*****FILE NOT FOUND*****\n";
}
else
{
fileFound = true;
i = 0;
fStudents >> studentRec.studentFName //initialize fStudents
>> studentRec.studentLName //...and load data
>> studentRec.testScore;
while(fStudents) //test fStudents for EOF
{
i++;
appendNode(pHead, studentRec); //add student node to end of list
fStudents >> studentRec.studentFName //modify fStudents
>> studentRec.studentLName //...and load data
>> studentRec.testScore;
}
listSize = i;
fStudents.close();
}
return fileFound;
}
void appendNode(tStudent*& pHead, tStudent student)
{
tStudent* pLastNode;
tStudent* pNewNode;
if(pHead != NULL)
{ // ***processing for all other nodes
pLastNode = findLastNode(pHead);
// other statements to get a node from the heap
// and populate the data fields and link field;
// add node to the list
pNewNode->studentFName;
pNewNode->studentLName;
pNewNode->testScore;
pNewNode->grade;
pNewNode->link = NULL;
}
else
{ // ***processing for first node of list
// statements to get a node from the heap
// and populate data fields and link field;
// this is first node in list
pNewNode = new tStudent;
pNewNode->studentFName;
pNewNode->studentLName;
pNewNode->testScore;
pNewNode->grade;
pNewNode->link = NULL;
}
}
tStudent* findLastNode(tStudent* pHead)
{
tStudent* pCurrent = pHead;
tStudent* pLastNode = NULL;
//traverse list and find address of last node
while( pCurrent != NULL){
pCurrent = pCurrent->link;
pCurrent = pLastNode;
}
return pLastNode;
}
void calculateGrade(tStudent* pHead)
{
tStudent* pCurrent = pHead;
// traverse list and process each node to determine letter grade assigned
while( pCurrent != NULL){
if( tStudent.testScore <= 100 && tStudent.testScore >= 90)
tStudent.grade = 'A';
else if( tStudent.testScore < 90 && tStudent.testScore >= 80)
tStudent.grade = 'B';
else if( tStudent.testScore < 80 && tStudent.testScore >= 70)
tStudent.grade = 'C';
else if( tStudent.testScore < 70 && tStudent.testScore >= 60)
tStudent.grade = 'D';
else if( tStudent.testScore < 60 && tStudent.testScore >= 0)
tStudent.grade = 'F';
else
tStudent.grade = '*';
}
pCurrent = pCurrent->link;
}
void printResult(tStudent* pHead) //traverses L-list and prints data component
{
tStudent* pCurrent = pHead;
//Heading Line
cout << endl;
cout << left
<< setw(25) << "Student Name"
<< right
<< setw(10) << "Test Score"
<< setw(7) << "Grade" << endl << endl;
// Detail Lines - traverse list and print each node
while(pCurrent !=NULL){
cout << tStudent.studentFName << " " << tStudent.studentLName << " " << tStudent.testScore << " " << tStudent.grade << endl;
pCurrent = pCurrent->link;
}
cout << endl;
}
[/cpp]
ok i created most of the code inside the functions from line 100 downward and here are my error's:
[IMG]http://i.imgur.com/iU2C5.png[/IMG]
[IMG]http://i.imgur.com/q9HOV.png[/IMG]
(feel free to double check the rest of the code from line 100 downward it you have time)
visual studio is muttering things about "left of 'blah blah' must have class/struct/union" etc etc (lol what does that mean)
For pointers you must use the "->" operator instead of the "." operator.
Sorry, you need to Log In to post a reply to this thread.