Saturday, May 5, 2007

STL Lists

A. Objective: Continue studying for the exam. Tackle the wonderful world of the STL linked list. Soooooo much easier than creating one from scratch.

B. Program:
Complete program with output

C. Comment:
This was basically a chance to redo the last lab. I created a list of strings and then opened a file to read the story from. I display it to the screen, sort it, reverse it, remove the repetition from it. I wish everything could be done with this much ease.

Wednesday, May 2, 2007

2D Array Operations

A.Objective: Practice my programming skills for the final. 2D Array Problem #18 p. 451

B.Program:
The Code

C.Comment:
Not having worked with a 2D array in a very long time, I had to use the book to jog my memory. Luckily the book had most of the code I needed and what it didn't, just required a little tweaking to get what the problem asked for. The display isn't all that pretty, but it gets the job done.

Lowest Score Drop

A.Objective: Practice my programming skills for the final. (2)Programming Challenge from Chapter 6

B.Program:
The Code

C.Comment:
This program took a little more thought. Also in order to follow their instructions, this program isn't written in the most practical way possible. There are things that could have made it shorter, such as putting the scores in a vector. This way it could have sorted it for me and found me the lowest score without all the if statements. I am proud of the way, I figured out how to calculate the average. The thought came to me, before I fell asleep.

Monday, April 30, 2007

Markup Program

A.Objective: Practice my programming skills for the final. 1)Programming Challenge from Chapter 6

B.Program:
My program

C.Comment:
I was successful in writing a program that takes from the user, the wholesale cost of an item and its markup percentage and calculate the retail cost of the item. It was basically a review on functions. I had to do some error checking and did have quite a few syntax errors that were solved easily.

Monday, April 9, 2007

April 10th

A. Objective: Write code in C++, very simple code that doesn't add to my already painful headache

B. My Program:
Visual Only: Hehehe-click here

C. I suceeded! My headache didn't get worse and I used C++ syntax.

Wednesday, April 4, 2007

April 5th

A.Objective: To write a simple program that actually has some kind of worth using my limited knowledge of C++.

B.Program
Take a gander right here:
.h file
.cpp file

C. Update: Chatted with Prof Coyle and I think I figured out my problem, I was doing integer division, so it was messing up my answer.

So, I was very proud of myself for writing a program that worked, until I discovered a problem in it. I'm so annoyed, I thought it was working correctly until I tested it out again before posting. The point of the program is to convert temperatures from celsius to fahrenheit and vice-a-versa. Well the conversion from celsius (C)to fahrenheit(F) works, but the fahrenheit to celsius doesn't. The only one that work for F to C is when I put in 32F and get 0C. Everytime I enter a degree in F, I get 0 C as the answer. Can someone help me figure out the problem as I have triple checked my formula and made all the changes I could think of and I can't figure it out.

Monday, April 2, 2007

April 3rd

A.Objective: Learn more about pure virtual functions for the test.

B.Program:
My .h files:
Student.h
EngStudent.h
All-in-One, i.e. output included

My .cpp files:
EngStudent.cpp

C.Comment:
This program from the book helped me to understand pure virtual functions better. I now know the syntax and why they are used. The base class in which the pure virtual function is declared can never be instantiated. I hope this will help me on the test.

Tuesday, March 27, 2007

March 29

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.

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.

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.

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:


#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.

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.

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 int grades; 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
.

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/