home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2731
Discussions: 186,608, Posts: 2,227,066, Members: 230,243
Free Scan: Update Your PC's Outdated Drivers to Optimize Performance
Old May 2nd, 2007, 02:13 AM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Mar 2007
Posts: 16
C++ class question

I am suppose to replace the iterator GetNextItem function with two seperate iterators with void advance(); ItemType CurrentItem() const;. Also the only wayto get the program to work is to make int num a global variable. Well I dont think my professor wants any global variables. He asks for a function that prints out to a file. Here is my program:

#include <fstream>
#include <iomanip>
#include <iostream>
using namespace std;
#include "list.cpp"
int num;
List myclass;
void printlist (ofstream&, List);
int main ()
{

ifstream enter;
ofstream output4;
//open data file
enter.open("enter.txt");
//if not open give error message
if (!enter)
{
cout << "Did not open enter.txt" <<endl;
return 1;
}
//open output file
output4.open("exit.txt");
//if not give error message
if (!output4)
{
cout << "Did not open exit.txt" << endl;
return 1;
}
// end of file loop with test (call ispresent).
enter >> num;
while (enter && !myclass.IsFull())
{
if (!myclass.IsPresent(num))
{
myclass.Insert(num);

}enter >> num;
}
printlist (output4, myclass);
cout << "THE END" << endl;




enter.close();
output4.close();
getchar();
return 0;
}
void printlist (ofstream& output4, List myclass)
{
myclass.Reset();
int limit = myclass.Length();
output4 << "Number of numbers: " << limit << endl;
output4 << "New List" << endl;
for (int count =0; count < limit; count++)
{
num = myclass.GetNextItem();
output4 << num << endl;
}
}

The GetNextItem Function in the class:

ItemType List::GetNextItem()
// Precondition:
// Iteration has been initialized by call to Reset;
// No transformers have been invoked since last call
// Postcondition:
// Returns item at the currentPos@entry in the list and
// resets current to next position or first position if
// last item is returned
{
ItemType item;
item = data[currentPos];
if (currentPos == length - 1)
currentPos = 0;
else
currentPos++;
return item;
}

sorry post is so long...dont know how to make seperate scrolling windows inside the post. Please do not tell me the answer...i need to learn this, so just point me in the right direction. Thanks guys.

firecookie2k is offline   Reply With Quote
TechIMO.com Ads - Login or register for less ads.
How many errors does your computer have?

You no longer need to guess! This free stability scan and registry cleaner download will give you a complete diagnosis of your Windows registry, identifying errors and conflicts.

FREE instant scan


Guest, Register Free! to remove this ad and get your tech support questions answered in minutes!
Old October 2nd, 2008, 06:52 PM     #2 (permalink)
Junior Member
 
Join Date: Mar 2007
Posts: 16
This is the errors that the compiler are calling out.
Code:
11 E:\addarray.cpp In file included from E:\addarray.cpp 
9 E:\sequence1.cpp expected nested-name-specifier before "namespace" 
9 E:\sequence1.cpp expected unqualified-id before "namespace" 
9 E:\sequence1.cpp expected `;' before "namespace" 
9 E:\sequence1.cpp expected unqualified-id before "namespace" 
10 E:\sequence1.cpp expected unqualified-id before '{' token 
39 E:\addarray.cpp expected unqualified-id at end of input 
39 E:\addarray.cpp expected `,' or `;' at end of input

firecookie2k is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Class of '06 EXreaction IMO Community 11 June 9th, 2006 11:23 PM
Help me pass class :) BustedAvi Graphic Design and Digital Photography 8 December 14th, 2004 10:37 AM
C++ Declaring A Class Morphios Webmastering and Programming 11 April 1st, 2003 06:34 PM
Which class to take??? Martoch Certification and Education 4 August 28th, 2002 10:03 PM
math class question (high school) Sweet IMO Community 12 May 29th, 2002 04:32 AM

Most Active Discussions
Is It Just Me? (535)
Misery Loves Company... (1849)
Why Does the MOON Grow Bigger as It.. (18)
heatsink issue (10)
New Mobo (18)
UPGRADING C/D DRIVE TO 250GB & .. (14)
1 internet. 1 house. 3 computer. ho.. (13)
Is This A Compatible Gaming PC? (18)
SSD's, RAID, and External Backup (7)
Recent Discussions
help! jumbled text and computer.. (0)
DFI socket 939 board acting up (5)
Building my first PC and need s.. (2)
32 or 64 bit vista (4)
Big problem with my PC (2)
system restore 'next' button wo.. (2)
firewall (1)
C++ compiler suggestions (4)
Official World of Warcraft Thre.. (4529)
FS: Dell 6000 laptop, modded 36.. (2)
Apple iPod touch 16 GB $200 (4)
Six 28-Disc Cross Design Black .. (4)


All times are GMT -4. The time now is 12:36 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28