0
Neillvan's Avatar, Join Date: Jan 2010
Newbie Member
Hi guys seems like all of you got the ideas uhmm can u help me out...

we were told to make an infinite Loop that stops using the escape key on the keyboard.


and im running out of time ..need to have it withing 10 hrs from now sorry for the rush request guys........i posted my prblem days before but non answered it ;d
0
Tannoji Banerjee's Avatar
Newbie Member
I want to know more things for java(jsp).Then what am i do?By the way,this site is very much help ful for me.really essencial.
0
adityapandey1207's Avatar, Join Date: Dec 2010
Newbie Member
Quote:
Originally Posted by subhasish View Post
When compiling a program, the compiler adds some optimizations that may cause your application to misbehave. For example consider the following code:

Code: CPP
// To avoid threads waiting on the critical section in vain</p>
<p>if (m_instance == NULL)</p>
<p>{</p>
<p> EnterCiriticalSection(pcs);</p>
<p> if (m_instance == NULL)</p>
<p> m_instance = new MyInstance();</p>
<p>}


The compiler may cache the second condition (m_instance == NULL) and not update the content of m_instance if it has been changed by another thread. The solution is to declare the instance with the volatile keyword. This tells the compiler to get the content of m_instance every time it is used and not cache its content.

The declaration is:

volatile MyInstance* m_instance;

Can u plz tell me what exactly is a volatile dataype and why its used???
0
A.Cloutier's Avatar, Join Date: Mar 2011
Newbie Member
A simple tip to always keep in mind, which will more than likely save a lot of frustration:
Plan out your program as thoroughly as possible on paper.

Being a current student at UAT, there have been many times I dove head first into a project and spent hours going through issues that I could have resolved had I thought through the project or assignment first on paper. Having been taught to use the UML to make diagrams, it often doesn't occur to me to continue to do so, however, even on paper, writing out what you want to do with your program and breaking it down into pieces helps immensely. No matter what language you prefer, planning helps.
0
spentak's Avatar, Join Date: Mar 2011
Newbie Member
This is something useful I learned doing a homework assignment:

Code:
#include <iostream>
#include <string>
using namespace std;


int main (int argc, char * const argv[]) 
{
	string theString = "This is the# string that /has invalid() characters in it";
	size_t illegalChar;
		
	cout << "\nThe String Before: " << theString << endl;
	
	illegalChar = theString.find_first_of("#$%^&*()!/[]{}");
	
	//Iterate through the string and replace all invalid characters with a space
	while (illegalChar != string::npos)
	{
		theString[illegalChar] = ' ';
		illegalChar = theString.find_first_of("#$%^&*()!/[]{}", illegalChar + 1);
	}
		
	cout << "\nThe String After: " << theString << endl;
	
    return 0;
}
spentak AKA Mark Price
0
aaron_yox's Avatar, Join Date: Jun 2011
Newbie Member
I am a UAT student, I am taking a C++ programming class. We're supposed to post something that we've found to be helpful to us.

What I've found helpful is not to just follow other coding and not to just read about programming. It tends to help a lot to write your own code. If you tend to just write down other code from someone else, copy it, or just read about it you won't learn as much as you would actually doing the code and creating a program that you did on your own. It's also good to post a snippet online to get some feedback so you know different ways of doing a simple code. Like for example lets do "Hello World".

To make sure you stop the window from closing right away, making it really hard to read what you have in the window, there are different ways of going through with this.

example 1:

Code:
#include <iostream>
 
using namespace std;
 
int main()
{
 
       cout << "Hello World\nPress enter key to continue..." << endl;
       cin.get();
       return 0;
}
example 2:

Code:
#include <iostream>
 
using namespace std;
 
int main()
{
 
      cout << "Hello World" << endl;
      system("PAUSE");
      return 0;
}
using namespace std is something helpful for less code. This makes it so that you don't have to type in std::cout every time you need that specfic code.

int main() you will see on every code you see. Every code has a main to store the "Main" program in.

cout lets you write a line to tell the user something of importance or instructions or something else.

\n in the " " writes on the next line like pressing enter in a word document.

endl is the end of the line you are writing on.

system("PAUSE") is something you can do to have the program pause where it is at and wait untill the user presses any key.

cin is retriving user input and the get() is getting that input. So the window doesn't close because it is waiting to get input from the user. By pressing enter it goes to the rest of the code.


There is two examples of how to stop the window from closing. So you see code can have different ways of being put in but also sometimes how you put the code in depends how well your program will run. Like some games that come out tend to run slow but if the code would be changed so that it would make the game (program) run smoother it would be much better.

I hope this helps and makes some newer programmers more intreged to start programming more.

Also if we wanted to have the user input some value then have it appear on the window it would look something like this.

Code:
#include <iostream>
 
using namespace std;
 
int main()
{
     int x;
     cout << "Please enter in a value: " << endl;
     cin >> x;
     cout << "\n\n" << "Here is your entered value: " << x << endl;
     system("PAUSE");
     return 0;
}
0
NateSwanson's Avatar, Join Date: Aug 2011
Newbie Member
Aaron,

Hello! I know we know each other from other classes (and we probably both know Mark too), but for sake of the assignment: I am another UAT student. It seems that you, Mark, and I all had the same assignment for our C++ Programming II course.

Now then, you are right in that the expression using namespace std; will save you from having to use as much code. However, there is another option still instead of having to type std::cout at the beginning of every line where you need to output text. You can also use the compiler directive:

Code:
using std::cout;
As an added benefit, I think (can anyone confirm?) that using the directive using std::cout; instead of using namespace std; will also save your program a small amount of memory because the compiler only has to include the specific instructions for how to implement cout into your program, rather than having to add the entire std library. This might not matter on small programs like our assignments, but I have a feeling that it is an important concept in larger programs where efficient use of memory can be an issue. Otherwise, why would I have seen so many people using just using std::cout; in example code rather than the entire using namespace std; version? (Can anyone answer this one too?)


One other thing too, Aaron. system("PAUSE") is indeed a way of pausing the program, but it is dependent on the operating system having a console command called pause available to the user. I don't know if Macs or UNIX/Linux/etc has such a command built-in. But if they don't, then system("PAUSE") won't work. However, I do have a solution that will work across all platforms that I built into my own simple library:

Code:
void pause()
{
    // Vars
    char *inputtedText = new char[1]; // std console input line = 80 chars max
    *inputtedText = '\0'; // default to empty

    // Display pause msg
    cout << "\nPress enter to continue...";

    // read new text into istream with getline
    istream & is = cin.getline(inputtedText, 1);

} // end pause
Then, after defining that function wherever best suits you to do so (I put mine in a separate file that contains my own personal library of often used functions), simply call the function wherever it is needed with a simple one line function call as follows:

Code:
pause();
Hope that helps! See you around online! Good luck in the rest of your courses!
0
akashtyagi36's Avatar, Join Date: Jan 2012
Newbie Member
hey rght now am studying in 12 with c++. i have gr8 interest in this.
now am facing problem in stack,queue,linked list and arrays.
would you help me?
reply me on akashtyagi36@yahoo.com
pls pls help if u can and pls reply
0
jorden's Avatar, Join Date: Jan 2012
Newbie Member
Thanks for the information. This information is really helpful for me.
0
ssaikaruna's Avatar, Join Date: Apr 2012
Newbie Member
Hi
I want video tutorials for C,C++,C#,JAVA,.Net.
Can anyone help me to get all these video tutorials pls.
Thank u
K.Sujatha