Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When using the term string literal, yes that is correct.

integers can also have literals. Example: int x = 123; In that the value 123 is a literal, sometimes called magic number or constant value.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I already told you how to stop the infinite loop -- press Ctrl+Z+Enter keys. That's what cin.eof() is looking for.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First, delete that compiler from your computer since the free trial has expired.

Next, download the free VC++ 2008 Express. This is NOT a trial version and does not expire.

As for the *.exe requiring Visual Studio, it depends on how you program. You can freely distribute the files located here (assuming default installation directory)
D:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT
That directory contains three dlls.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

worked for me. delete all references to SIZE and call resize() after you know how many elements are to be entered.

how many tests will you be entering? 5
enter score for test 1 : 5
enter score for test 2 : 3
enter score for test 3 : 1
enter score for test 4 : 2
enter score for test 5 : 4
5
4
3
2
1
your average score is: 3
Press any key to continue . . .
int main()
{
     int count=0;
     int testNum=0;
     vector<int> test;
     int Avg1=0;
     double Avg2=0;
     
     cout <<"how many tests will you be entering? ";
     cin >> testNum;
     test.resize(testNum);
     for (count=0; count < testNum; count++)
     {
      cout << "enter score for test "<< count+1<<" : ";
      cin >> test[count];
      Avg1+=test[count];
     }
     Avg2=static_cast<int> (Avg1)/testNum;
     
     testSort(test);
     
//this is to show the grades in acending order

     for (int count = 0; count < testNum; count++)
     {
          cout<< test[count] << "\n";
     }
     
     cout << "your average score is: " << Avg2<<endl;
      
     
     system("pause");
     return 0;
}

void testSort(vector<int>& test)
{
     
     for (unsigned int startScan = 0;startScan < (test.size()-1); startScan++)
     {
         for(unsigned int count = startScan +1; count < test.size(); count++)
         {
          if (test[startScan] > test[count] )
             {
                 int temp = test[startScan];
                 test[startScan] = test[count];
                 test[count] = temp;
             }
          }
     }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Why the selection sort output not appear?
Because it is never called.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It is not the string but the text inside the quotes. It could be either c or c++. cout << "Hello World\n"; That is also a literal.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>So can anyfren tell me how to control string output to that location?
If you want to change the text in the file itself, then you will have to rewrite the entire file. When you come across the line "Set wallpaper" then write out the new text into the new file.
Here is some pseudocode for you to use.

open original file
open new output temp file

for each row in input file
   call fgets() to read the line
   check for "Set wallpaper"
   if check is true then write new text to output file
   otherwise if check is false then just write the entire row to output file
end of while loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A literal is a string of characters inside quotes. For example char str[] = "Hello World"; In the above, "Hello World" is considered the literal.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It is my mispelling of int. I hit the wrong keys and didn't notice it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what exactly is "ubt?" I can't find it in my book.

I have no idea either. Where did you see that ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You get that error because you are passing a vector and the function wants an int array. Not the same thing. So just change the function to this:

Note, this doesn't need the second parameter SIZE because vectors know their size.

void testSort(vector<int>& test)
{
    for (int startScan = 0;startScan < (test.size()-1); startScan++)
    {
         for(int count = startScan +1; count < test.size(); count++)
         {
              if (test[startScan] < test[count])
             {
                  int temp = test[startScan];
                  test[startScan] = test[count];
                  test[count] = temp;
             }
          }
     }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, debugger show me the values. I use VC++ 2008 Express, which has the best debugger I have ever found.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is how I code that function.

void testSort(int test[], int SIZE)
{
    for (startScan = 0;startScan < (SIZE-1); startScan++)
    {
         for(int count = startScan +1; count <SIZE; count++)
         {
              if (test[startScan] < test[count])
             {
                  int temp = test[startScan];
                  test[startScan] = test[count];
                  test[count] = temp;
             }
          }
     }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 27 and 29: what is that '/' character doing there? Your compiler whould have given you an error on those lines.

To stop the loop at line 72 you have to enter Ctrl+Z + Enter keys.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Not sure if I can answer your specific question, but a couple observations:

line 121: the value of bracket_nr is -1 when that line is hit, so the loop does nothing

line 126: The value of close_char is -52, which of course is an illegal index value.

line 130: array close is uninitialized and just contains random data. You should initialize it to 0 when declared.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It required the gcc comcompiler, which I don't have. But after uncompressing the file read the readme.txt file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post the code you have tried. When the first letter is 'o' then just call strcpy() to copy the entire word. But whether that will work or not all depends on how you declared the two arrays. Post how you declared the two arrays and the rest of your program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have no idea what it is doing either, but it displays an interesting map.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

delete the loop on line 36 and only leave line 37. Then declare variable i at the top of the function and initialize it to 0. Increment the value of i after line 37.

void displayMenu (int choice)
{
    int i = 0;
    do
    {
             // display menu here, not shown

             if( choice == 1)
             {
                 addCourse(addList[i]);
                 ++i;
            }
  // other code here

Looking at the rest of the menu items I suspect it will be a little easier if you used a linked list instead of an array of courses. To delete a course you would just have to delete the node in the linked list. In an array you will have to move all array elements up one to overwrite the course you want to delete. It can be done, but its just a tad bit more difficult.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 12: you are attempting to use string as both c++ object type and a variable name. You have to rename it to something else

line 13: why are you using character arrays here? You can just use std::string class

string fileword, fileline;

The loop that starts on line 25 is coded wrong because eof() doesn't work the way you think. Most new programmers make this mistake and I'm not sure if its due to inexperience of terrible instructors.

The solution to this problem involved stringstream class, which will split up an entire line into individual words. This code is not 100% correct but gives you an idea of what to do.

#include <sstream>

<snip>
string word, line;
while( getline(file, line) )
{
     stringstream str(line);
     while( str >> word)
     {
           if( word == WordToFind)
           {
                ++count;
                cout << line << "\n";
          }
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>void addCourse (courseInfo addList[])
It would be better if all you did was pass only one array element and pass it by refernece

void addCourse (courseInfo& addItem)
{
	
    cout << "Enter the course title:" << endl;
    cin >> addItem.courseName;
    cout << "Enter the course CRN:" << endl;
    cin >> addItem.crn;
    cout << "Enter the start time for this course:" << endl;
    cin >> addItem.startTime;
    cout << "Enter the end time for this course:" << endl;
    cin >> addItem.endTime;
    cout << "Enter the days of the week the course occurs on:" << endl;
    cin >> addItem.days;
}

Then you call the above like this: I'm only showning a loop here for simplicity, so make it however complicated you need it.

int main()
{
    int i;
    for(i = 0; i < NumElements; i++)
    {
         addCourse (addList[i]);
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you might try #pragma optimize(...) See this.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 36 and 37 -- similar lines that follow too. Too many if's -- should only have one 'if'. You are also missing the braces { and } when more than one line within the if statement

else 
if(room == 1)
{
    if(floor <= 11) 
    {
            rcost = 65;
           cout << rcost; 
    }
}
else 
// etc. etc

You can shorten up the above a little bit like this:

else 
if(room == 1 && floor <= 11)
{
      rcost = 65;
      cout << rcost; 
}
else 
// etc. etc
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
jephthah commented: you're way too nice +1
Salem commented: Oh so simple, why didn't they think of that? +16
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

move lines 10 and 11 up to between lines 1 and 2.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Please help me!! I recently finished my C#.Net course, and need to start writing programs. But now the problem is, I honestly don't know where and how to start. Please advise me!!

I hop you mean you want to start writing programs for profit (e.g. professionally). Have you got your college BS/BA degree yet? If not, then get one.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

fseek is causing the problem..

Yes, that is the major problem.
Here is the entire line that he is trying to read Before Renamesk . . . . . . . . . . . : 255.255.255.0

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 19: >> if !(ScheduledIn == ("y" || "n" || "Y" || "N"))

Formed wrong. if !(ScheduledIn == "y" ||ScheduledIn == "n" || ScheduledIn =="Y" ||ScheduledIn == "N")) The other if statements have similar problem. You can shorten it up by converting to upper-case first

ScheduledIn = toupper(SchecduledIn);
if (ScheduledIn =="Y" || ScheduledIn == "N"))
{

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is there another way you can confirm the entire file was read if you don't know ahead of time what's in the file?

After the loop finishes, call tellg() to get the current pointer location (-1 is failure), then seek to the end of the file and call tellg() again. Compare the two values.

Or just simply check eof() after the loop finishes.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It is not necessary to state std::cout on every line -- most programmers code a using statement at the top

#include <iostream>
using std::cout;

int main()
{
	cout << "Hello there.\n";
	cout << "Here is 5: " << 5 << "\n"
	cout << "The manipulator std::endl";
	cout << "writes a new line to the screen.";
	cout << std::endl;
	cout << "Here is a very big number:\t << 7000";
	cout << std::endl;
	cout << "Here is the sum of 8 and 5:\t";
	cout << 8+5 << std::endl;
	cout << "Here's a fraction: \t\t";
	cout << (float) 5/8 << std::endl;
	cout << "And a very very big number:\t";
	cout << (double) 7000 * 7000 << std::endl;
	cout << " Don't forget to replace Jesse Liberty ";
	cout << "with your name...\n";
	cout << "Jesse Liberty is a C++ programmer!\n";
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Could anyone tell me about what are the test cases i should do?
Test everything.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

depends -- what compiler are you using. If Microsoft they are installed with the compiler. VC++ 2005 Express you will need to download the Windows Platform SDK to get them, which is a huge download.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how about this: cout << setw(40) << left << "John" << setw(40) << "Smith" << "\n";

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Any ideas what I should request for a salary for an entry level developer
Yes, ask for at least $1,000,000.00 USD per hour :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here's how to do it. fprintf(myfile,"Set wallpaper= \"%s\"\n",textbox1->text);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try using unsigned char

int main()
{
unsigned char ch = '—';
cout << static_cast<int>(ch) << "\n";
if( isprint(ch))
    cout << "TRUE\n";
else cout << "FALSE\n";
}

output is 151
FALSE

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I guess I didn't read it very well either. I didn't notice in the first problem the loop counter was increased by 3 on each loop iteration. So I flunked that question.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> it does not say non-believers will perish
True -- and I think its because their status is ambiguous as far as we are concerned.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you want to check for printable characters you can use the isprint() macro in ctype.h. What is the decimal value of the '—' you are talking about.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If the loop terminates does it really matter whether eof was reached or the file was corrupt? Yes, it might in more complex programs because if the program detected corruption then it could just abort the entire transactions and not do anything except issue an error message.

So to use eof() at all would depend on the complexity of the program. After the loop ends you could test for eof() just to insure eof actually occurred. But that would be outside the loop, not part of the loop.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sneek, you missed the point (and so did AD), he made a claim - I just wanted him to back up the claim. Your quote does not back up his statement. The claim was roughly 'non-xtians are doomed - it all over the bible'. I just wanted him to support his argument; I am certainly not interested in doing his research for him (or for you for that matter).

[edit]OMG I just noticed that I edited your post instead of quoting it. My deapest apologies for my error -- AD [/edit]

.

I already told you that I have no intention of turning this thread into any type of religious war. I'll say it again -- You want a quote: just ONE is John 3:16

For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life.

There are similar claims all over the New Testiment. Also note that this only applies to people born after Christ was born and who are aware of his teachings. That means everyone born in BC, all children under certain age, and people who never heard of Christ are exempt. So the contention that everyone is doomed is not correct.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you look at the standard ascii chart you will see that it contains 256 entries, some are printable but most are not. This ascii chart only contains characters in the English language. Other languages will use different charts to accommodate the language that is installed on the computer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> Do you ever find a good occasion to use eof ()
I haven't ever had an occations to use it. But that doesn't mean there is no use for it at all.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Either you are using a crappy compiler or you did not post the current code:

ticTacToe.cpp
>>TicTacToe::ticTacToe()
Spelled wrong.

TicTackToe.h
missing the constructors referenced in the *.cpp implementation file.

I'm giving up now.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) 3 2 8 7 1 5 6 0 0 0 0 0 0 0 0 The reason for all those 0s at the end is that the compiler will initialize any unspecified array elements with 0 as long as there is at least one initializer

Example: int array[15] = {0} is often used to initialize all elements to 0 even though only the first is specified.

I have no idea were you got your answer :)

Your problem with the rest of the questions was you did not read the questions very carefully.

>>Write the statement to declare an object being used to read from a fill
You are to declare the object, not call the open statement. So the correct answer is ifstream fin; >>Write the statement to read in an integer
You wrote a statement to OUTPUT the integer, not read it. The correct answer is fin >> num1;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Just hit preview and Ancient Dragon beat me to it with the same advice. :(

Yes, because I think most experienced programmers will agree that is the best way to code it. There are other ways, but IMO they are just more clumbsy and less efficient.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is the way you formed that while loop -- it reads the last entry in the file twice. Here is the correct way to code it. Notice that eof() is not necessary.

while(empFile >> thisSalary)
	{
		emp[i].setSalary(thisSalary);    //assigns to the array
		cout << emp[i].getSalary() << endl;   //for test purposes
		i++;
	}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, vectors are very easy to use. You would loop through the vector just like you would loop through any other normal array

for(int i = 0; i < theList.size(); i++)
{
    if( theList[i] == "Alkesh" )
    {
       cout << "Found at array element number " << i << "\n";
    }
}

Tutorial here

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

maybe you need to read this again

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you use the vector class you don't have to know how many words there ahead of time. Just read the file once and add each word to the vector -- it will expand as necessary to contains all the strings

#include <vector>
#include <string>
#include <fstream>
#include <iostream>
using namespace std;

int main()
{
    vector<string> theList;
    string word;
    ifstream infile("filename.txt");
   while( infile >> word)
       theList.push_back(word);
   // after the above loop finishes the vector will
   // contain all the words.
}