A. Objective: Continue working on sorting my linked list.
B. Program:
This link contains the .h .cpp and my output:
All-in-one
This is my cpp file:
.Cpp file
This is my .h file:
.h file
C. Comment: Thanks to Abishek's comment, I was able to sort my original list. However, I decided to add another node to my list and now the new node doesn't sort properly. I don't know what I did or what I haven't done to cause this problem. It seems everytime I add something new, the original has to break down.
Tuesday, March 27, 2007
Sunday, March 25, 2007
March 27
A.Objective: Get more comfortable with classes: defining constructors with arguments.
B. Program: Here are my files:
Click to see :Header File
Click to see:CPP File
Click to See: File with output
Scroll all the way to the end of the file to view the output.
C. Comment
In this program, I used an array of my class object to store my various friends, names and university names It took me a while to figure out how to define the constructor. I kept running into problems with the syntax in two places: where I had defined my constructor (.h) and where I had declared my array of the friends class (.cpp). I also originally started out with a fourth category of information, my friends' phone numbers. However, I was having problems because it is so many digits. So, I tried creating an array of ints to hold the numbers, but I still got many errors and therefore decided to tackle that another day.
B. Program: Here are my files:
Click to see :Header File
Click to see:CPP File
Click to See: File with output
Scroll all the way to the end of the file to view the output.
C. Comment
In this program, I used an array of my class object to store my various friends, names and university names It took me a while to figure out how to define the constructor. I kept running into problems with the syntax in two places: where I had defined my constructor (.h) and where I had declared my array of the friends class (.cpp). I also originally started out with a fourth category of information, my friends' phone numbers. However, I was having problems because it is so many digits. So, I tried creating an array of ints to hold the numbers, but I still got many errors and therefore decided to tackle that another day.
Thursday, March 22, 2007
March 22
A. Objective: Moving on to more fun things. i.e. classes!!! So this was my first attempt at classes. Yes, I wrote it, No, I didn't write it today It's from a few months back. I thought I should revisit it and remind myself what I wrote.
B. Program:
Click Here to see the program
C. Comment:
So, this program was written with four files. A constants file, a class header file, a class implementation file and a main file. This program keeps track of employees at a store. Their first, middle initial, last name, employee ID, payrate, comission and what type of position they have. The information is read from a file, memory is allocated dynamically and the information is displayed to the screen. It's simple, but rather long.
B. Program:
Click Here to see the program
C. Comment:
So, this program was written with four files. A constants file, a class header file, a class implementation file and a main file. This program keeps track of employees at a store. Their first, middle initial, last name, employee ID, payrate, comission and what type of position they have. The information is read from a file, memory is allocated dynamically and the information is displayed to the screen. It's simple, but rather long.
Monday, March 19, 2007
March 20
A. Objective: To enhance my previous linked list program. I wanted to be able to sort the list by country code number.
B. Result: This first program is the addition of a new node and another field in the linked list:
The following link is to my .cpp file where I tried sorting the linked list.
My .cpp file
C. Comment: I was never able to sort the list. When I tried doing so, the last node did not show up in the output. I would really like to figure out how to sort the linked list. I will try working on it further but at this point I am stuck.
B. Result: This first program is the addition of a new node and another field in the linked list:
#ifndef MARCH20_H
#define MARCH20_H
#include <string>
using namespace std;
struct Abroad
{
string country;
int countryCode;
string currencyType;
Abroad *next;
};
class Country
{
private:
Abroad *head;
public:
void setAbroad (string, int, string);
void showInfo ();
Country ()
{head = NULL;}
};
#endif
#include <iostream>
#include <iomanip>
#include <string>
#include "march20.h"
using namespace std;
int main ()
{
Country pays;
string cname1 = "France ";
string cname2 = "India ";
string cname3 = "Denmark";
string FrenchCurrency = "Euro";
string IndianCurrency = "Rupee";
string DanishCurrency = "Danish Krone";
pays.setAbroad (cname1, 33, FrenchCurrency);
pays.setAbroad (cname2, 91, IndianCurrency);
pays.setAbroad (cname3, 45, DanishCurrency);
pays.showInfo ();
return 0;
}
void Country :: setAbroad (string CName, int cCode, string currencyT)
{
Abroad *newAbroadPtr, *nodePtr;
newAbroadPtr = new Abroad;
newAbroadPtr->country = CName;
newAbroadPtr->countryCode = cCode;
newAbroadPtr->currencyType = currencyT;
newAbroadPtr->next = NULL;
if (!head)
head = newAbroadPtr;
else
{
nodePtr = head;
while (nodePtr->next)
{
nodePtr = nodePtr->next;
}
nodePtr->next = newAbroadPtr;
}
}
void Country :: showInfo ()
{
Abroad *nodePtr;
nodePtr = head;
cout <<"----------------------------------------\n";
cout <<" Country " <<>country;
cout <<>countryCode;
cout <<>currencyType <
nodeptr="nodePtr-">next;
}
}
----------------------------------------
Country Calling Code Currency
----------------------------------------
France 33 Euro
India 91 Rupee
Denmark 45 Danish Krone
The following link is to my .cpp file where I tried sorting the linked list.
My .cpp file
C. Comment: I was never able to sort the list. When I tried doing so, the last node did not show up in the output. I would really like to figure out how to sort the linked list. I will try working on it further but at this point I am stuck.
Wednesday, March 7, 2007
I figured out linked lists-sorta
A. Objective : Write a functioning Linked List Program
B. Result:
Source Code:
#ifndef LINKEDLISTFUN_H
#define LINKEDLISTFUN_H
#include string // the angle brackets once again missing for the purpose of the blog
using namespace std;
struct Abroad{
string country;
int id;
Abroad *next;
};
class Country{
private:
Abroad *head;
public:
void setAbroad (string, int);
void showInfo ();
Country ()
{head = NULL;}
};
#endif
#include iostream //angle brackets missing for blog
#include string // same here
#include "LinkListFun.h"
using namespace std;
int main ()
{
Country pays;
string cname1 = "France";
string cname2 = "India";
pays.setAbroad (cname1, 5);
pays.setAbroad (cname2, 8);
pays.showInfo ();
return 0;
}
void Country :: setAbroad (string CName, int id)
{
Abroad *newAbroadPtr, *nodePtr; newAbroadPtr = new Abroad;
newAbroadPtr->country = CName; newAbroadPtr->id = id;
newAbroadPtr->next = NULL;
if (!head)
head = newAbroadPtr;
else
{
nodePtr = head;
while (nodePtr->next)
{
nodePtr = nodePtr->next;
}
nodePtr->next = newAbroadPtr;
}
}
void Country :: showInfo ()
{
Abroad *nodePtr;
nodePtr = head;
while (nodePtr) {
cout << "Country: " <<>country <<>id << endl;
nodePtr = nodePtr->next;
}
}
Output:
Country: France
ID: 5
Country: India
ID: 8
C. Comment: I finally got a functioning linked list program to work. It's rather simple and I used code from the Gaddis Book. I finally feel like I understand that the head has to point to the beginning of the list all the time and that if you want to traverse the list, you need to have another pointer. The head should intialized to NULL inside the class constructor and you need an instance of the class declared in main to access the class's functions.
B. Result:
Source Code:
#ifndef LINKEDLISTFUN_H
#define LINKEDLISTFUN_H
#include string // the angle brackets once again missing for the purpose of the blog
using namespace std;
struct Abroad{
string country;
int id;
Abroad *next;
};
class Country{
private:
Abroad *head;
public:
void setAbroad (string, int);
void showInfo ();
Country ()
{head = NULL;}
};
#endif
#include iostream //angle brackets missing for blog
#include string // same here
#include "LinkListFun.h"
using namespace std;
int main ()
{
Country pays;
string cname1 = "France";
string cname2 = "India";
pays.setAbroad (cname1, 5);
pays.setAbroad (cname2, 8);
pays.showInfo ();
return 0;
}
void Country :: setAbroad (string CName, int id)
{
Abroad *newAbroadPtr, *nodePtr; newAbroadPtr = new Abroad;
newAbroadPtr->country = CName; newAbroadPtr->id = id;
newAbroadPtr->next = NULL;
if (!head)
head = newAbroadPtr;
else
{
nodePtr = head;
while (nodePtr->next)
{
nodePtr = nodePtr->next;
}
nodePtr->next = newAbroadPtr;
}
}
void Country :: showInfo ()
{
Abroad *nodePtr;
nodePtr = head;
while (nodePtr) {
cout << "Country: " <<>country <<>id << endl;
nodePtr = nodePtr->next;
}
}
Output:
Country: France
ID: 5
Country: India
ID: 8
C. Comment: I finally got a functioning linked list program to work. It's rather simple and I used code from the Gaddis Book. I finally feel like I understand that the head has to point to the beginning of the list all the time and that if you want to traverse the list, you need to have another pointer. The head should intialized to NULL inside the class constructor and you need an instance of the class declared in main to access the class's functions.
Monday, March 5, 2007
Linked Lists Confusion
A. Figure out linked lists
B. Snippet of Code from a program I wrote in the summer, for my class
The structs that accompany this code are missing. There are two structs that are need in this linked list. One is Patient and the other Clinic. The next pointer is in the Clinic and the head (listPtr) is in the Clinic.
void insertNode (struct Clinic* clinicPtr, struct Patient* newPatientPtr)
{
struct Patient *current = NULL; struct Patient *previous = NULL;
if (clinicPtr->listPtr == NULL) {
clinicPtr->listPtr = newPatientPtr; clinicPtr->listPtr->nextPatPtr = NULL;
}
else {
previous = current = clinicPtr->listPtr;
while ((current != NULL) && (current->ID <>ID)) {
previous = current; current = current->nextPatPtr;
}
if (current == clinicPtr->listPtr) {
clinicPtr->listPtr = newPatientPtr; clinicPtr->listPtr->nextPatPtr = current;
}
else {
previous->nextPatPtr = newPatientPtr; newPatientPtr->nextPatPtr = current;
}
}
}
There is no output specifically for this code, there was a display function that showed output the screen for the whole program.
C. As somone who has a very hard time with the subject, I am trying to understand my previous code to help me with new code. This linked list inserted nodes by the ID number of the patient. So it sorted it for you.
B. Snippet of Code from a program I wrote in the summer, for my class
The structs that accompany this code are missing. There are two structs that are need in this linked list. One is Patient and the other Clinic. The next pointer is in the Clinic and the head (listPtr) is in the Clinic.
void insertNode (struct Clinic* clinicPtr, struct Patient* newPatientPtr)
{
struct Patient *current = NULL; struct Patient *previous = NULL;
if (clinicPtr->listPtr == NULL) {
clinicPtr->listPtr = newPatientPtr; clinicPtr->listPtr->nextPatPtr = NULL;
}
else {
previous = current = clinicPtr->listPtr;
while ((current != NULL) && (current->ID <>ID)) {
previous = current; current = current->nextPatPtr;
}
if (current == clinicPtr->listPtr) {
clinicPtr->listPtr = newPatientPtr; clinicPtr->listPtr->nextPatPtr = current;
}
else {
previous->nextPatPtr = newPatientPtr; newPatientPtr->nextPatPtr = current;
}
}
}
There is no output specifically for this code, there was a display function that showed output the screen for the whole program.
C. As somone who has a very hard time with the subject, I am trying to understand my previous code to help me with new code. This linked list inserted nodes by the ID number of the patient. So it sorted it for you.
Saturday, March 3, 2007
March 6, 2007
A. Goal: Better understanding of the vector STL
B. Result:
The Program
The blog thinks the angle brackets are HTML code and deesn't display whatever follows the include, so I left them out in the blog. They were in the original program. There are angle brackets missing in several places for the purpose of the blog.
#include iostream
#include iomanip
#include vector
using namespace std;
int main ()
{
int NUM_OF_STUDENTS = 0;
cout << "How many students are in your class?\n"; cin >> NUM_OF_STUDENTS;
vector intgrades; Again can't display the angle brackets
cout <<"Enter the grades for each of your student\n"; for (int i = 0; i <> cout << "Student ID" < cout <<"------------------------------------\n"; for (int i = 0; i <> }
return 0;
}
The Output
How many students are in your class?
5
Enter the grades for each of your student
Student ID:1 87
Student ID:2 68
Student ID:3 99
Student ID:4 87
Student ID:5 88
----------------------------------
Student ID Grade
------------------------------------
1 0
2 1
3 2
4 3
5 4
C. I spent about an hour or more on this program, it's suppose to be simple, but I couldn't figure out why my data wasn't being stored in the vector. When I went to print it the screen it just would not show the data that was supposed to be in there. I NEED more practice and more understanding of vectors as I apparently cannot get this to work out correctly. I did get it to work if I used array notation, but if I wanted to used the push_back function, it wouldn't work.
B. Result:
The Program
The blog thinks the angle brackets are HTML code and deesn't display whatever follows the include, so I left them out in the blog. They were in the original program. There are angle brackets missing in several places for the purpose of the blog.
#include iostream
#include iomanip
#include vector
using namespace std;
int main ()
{
int NUM_OF_STUDENTS = 0;
cout << "How many students are in your class?\n"; cin >> NUM_OF_STUDENTS;
vector int
cout <<"Enter the grades for each of your student\n"; for (int i = 0; i <> cout << "Student ID" <
return 0;
}
The Output
How many students are in your class?
5
Enter the grades for each of your student
Student ID:1 87
Student ID:2 68
Student ID:3 99
Student ID:4 87
Student ID:5 88
----------------------------------
Student ID Grade
------------------------------------
1 0
2 1
3 2
4 3
5 4
C. I spent about an hour or more on this program, it's suppose to be simple, but I couldn't figure out why my data wasn't being stored in the vector. When I went to print it the screen it just would not show the data that was supposed to be in there. I NEED more practice and more understanding of vectors as I apparently cannot get this to work out correctly. I did get it to work if I used array notation, but if I wanted to used the push_back function, it wouldn't work.
Thursday, March 1, 2007
Blog intro to Blog
Thursday, March 1 2007
Our computer science professor wants us to set up blog where we can practice, practice, practice our programming. As a person who doesn't really understand the concept, this a good and a bad thing. It's good because I really do need the practice, even if it is just to get through this course. It's bad because I'm lazy and I don't really like programming so now I am being forced to program.
Another good thing about this is that all the programs don't have to work and I can spend 15-30mins on this assignment, which isn't very long.
I do think this is an innovative idea to get us to program, so kudos to Prof Coyle.
Let the pain begin!
http://engr.smu.edu/~coyle/cse2341/
Our computer science professor wants us to set up blog where we can practice, practice, practice our programming. As a person who doesn't really understand the concept, this a good and a bad thing. It's good because I really do need the practice, even if it is just to get through this course. It's bad because I'm lazy and I don't really like programming so now I am being forced to program.
Another good thing about this is that all the programs don't have to work and I can spend 15-30mins on this assignment, which isn't very long.
I do think this is an innovative idea to get us to program, so kudos to Prof Coyle.
Let the pain begin!
http://engr.smu.edu/~coyle/cse2341/
Labels:
annoyance,
challenge,
CSE,
innovative,
mildly fun,
work
Subscribe to:
Comments (Atom)