🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C++ Workshop - Week 1 (Ch. 1 & 2) - Quizzes and Extra Credit

Started by
27 comments, last by Dbproguy 16 years, 2 months ago
hi,

I have not changed something in my standard library before.
This is my vcproj file :

<?xml version="1.0" encoding="Windows-1252"?><VisualStudioProject	ProjectType="Visual C++"	Version="8,00"	Name="c++Workshop"	ProjectGUID="{90627FF6-BF7C-4548-924E-D7AD2B70BBCC}"	RootNamespace="cWorkshop"	Keyword="Win32Proj"	>	<Platforms>		<Platform			Name="Win32"		/>	</Platforms>	<ToolFiles>	</ToolFiles>	<Configurations>		<Configuration			Name="Debug|Win32"			OutputDirectory="$(SolutionDir)$(ConfigurationName)"			IntermediateDirectory="$(ConfigurationName)"			ConfigurationType="1"			CharacterSet="1"			>			<Tool				Name="VCPreBuildEventTool"			/>			<Tool				Name="VCCustomBuildTool"			/>			<Tool				Name="VCXMLDataGeneratorTool"			/>			<Tool				Name="VCWebServiceProxyGeneratorTool"			/>			<Tool				Name="VCMIDLTool"			/>			<Tool				Name="VCCLCompilerTool"				Optimization="0"				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"				MinimalRebuild="true"				BasicRuntimeChecks="3"				RuntimeLibrary="3"				UsePrecompiledHeader="0"				WarningLevel="3"				Detect64BitPortabilityProblems="true"				DebugInformationFormat="4"			/>			<Tool				Name="VCManagedResourceCompilerTool"			/>			<Tool				Name="VCResourceCompilerTool"			/>			<Tool				Name="VCPreLinkEventTool"			/>			<Tool				Name="VCLinkerTool"				LinkIncremental="2"				GenerateDebugInformation="true"				SubSystem="1"				TargetMachine="1"			/>			<Tool				Name="VCALinkTool"			/>			<Tool				Name="VCManifestTool"			/>			<Tool				Name="VCXDCMakeTool"			/>			<Tool				Name="VCBscMakeTool"			/>			<Tool				Name="VCFxCopTool"			/>			<Tool				Name="VCAppVerifierTool"			/>			<Tool				Name="VCWebDeploymentTool"			/>			<Tool				Name="VCPostBuildEventTool"			/>		</Configuration>		<Configuration			Name="Release|Win32"			OutputDirectory="$(SolutionDir)$(ConfigurationName)"			IntermediateDirectory="$(ConfigurationName)"			ConfigurationType="1"			CharacterSet="1"			WholeProgramOptimization="1"			>			<Tool				Name="VCPreBuildEventTool"			/>			<Tool				Name="VCCustomBuildTool"			/>			<Tool				Name="VCXMLDataGeneratorTool"			/>			<Tool				Name="VCWebServiceProxyGeneratorTool"			/>			<Tool				Name="VCMIDLTool"			/>			<Tool				Name="VCCLCompilerTool"				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"				RuntimeLibrary="2"				UsePrecompiledHeader="0"				WarningLevel="3"				Detect64BitPortabilityProblems="true"				DebugInformationFormat="3"			/>			<Tool				Name="VCManagedResourceCompilerTool"			/>			<Tool				Name="VCResourceCompilerTool"			/>			<Tool				Name="VCPreLinkEventTool"			/>			<Tool				Name="VCLinkerTool"				LinkIncremental="1"				GenerateDebugInformation="true"				SubSystem="1"				OptimizeReferences="2"				EnableCOMDATFolding="2"				TargetMachine="1"			/>			<Tool				Name="VCALinkTool"			/>			<Tool				Name="VCManifestTool"			/>			<Tool				Name="VCXDCMakeTool"			/>			<Tool				Name="VCBscMakeTool"			/>			<Tool				Name="VCFxCopTool"			/>			<Tool				Name="VCAppVerifierTool"			/>			<Tool				Name="VCWebDeploymentTool"			/>			<Tool				Name="VCPostBuildEventTool"			/>		</Configuration>	</Configurations>	<References>	</References>	<Files>		<Filter			Name="Source Files"			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"			>			<File				RelativePath=".\display.cpp"				>			</File>		</Filter>		<Filter			Name="Header Files"			Filter="h;hpp;hxx;hm;inl;inc;xsd"			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"			>		</Filter>		<Filter			Name="Resource Files"			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"			>		</Filter>	</Files>	<Globals>	</Globals></VisualStudioProject>


But there maybe is an error in the standard library, I maybe have to reinstall it?


amoK

EDIT :
I have tried to compile the .cpp file from an other text editor, on a shell, but I´m getting the same errors.
Maybe I have changed something in the stdandard library.
Is there a possibility to just download the include files of the standard lib?

amoK

[Edited by - am0K on June 11, 2006 3:15:22 AM]
Advertisement
Heya am0K,

I compared your vcproj file with mine and they are for the most part identical. As well, your code compiles and runs fine on my machine. So whatever the problem is, its not with your code or project, so it almost has to be with your visual studio installation or configuration.

Did you accept all the defaults when installing? Are you SURE you didn't change anything in the visual studio header files?

At this point, I'm afraid I cant offer much more help. All the "normal" problems seem to be ok. You might try re-installing Visual C++. And no, I don’t believe you can just install the header files. You can, however, re-install with the same executable you used to install it, and it might even have a "repair" mode installation.

Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Hi,

Ok, thanks for the help JWalsh, I'll try to reinstall my VC++.


amoK
Trying to do this without looking:)

What is an interpreter?
An interpreter reads a pgm and runs it as it is being read.

What is a compiler?
A compiler takes source code, turns it into an object file and then links it to produce an executable.

Why is compiled code faster than translated code?
Because compiled code contains code that has already been translated into an object file and linked (both of those processes take time).

What does structured programming (procedural programming) consist of?
Smaller, broken down tasks that refer to each other when necessary.

What were the primary problems object oriented programming was designed to solve?
Previously, you were unable to associate specific data with the proper structures easily. With object-oriented programming, you can do this.

What are the three pillars of object oriented programming? Does C++ support them all?
Encapsulation, Inheritance and Polymorphism, and yes.

What is encapsulation?
The act of having self-contained units.

What is inheritance?
Being able to extend upon things that already exist.

What is polymorphism?
The ability for things to take on different forms.

Should you learn C before C++, why or why not?
They are extremely similar, so it is not necessary.

What is the FIRST question you ask when beginning your designs?
"What are my exact goals?"

What is the SECOND question you ask when beginning your designs?
"Do I need to create custom software to achieve these goals?"

What are the two primary steps in creating an executable? What is the output of each step?
Compiling your code, which produces an object file, and then linking that file, which creates an executable.

If your compiler requires <iostream.h> does it follow the ANSI standard? What IS the standard?
No it does not, the standard is simply <iostream>.


Chapter 2

When you issue a command to compile your code, what is run first? What does it do?
The preprocessor looks for '#' commands.

What symbol indicates a preprocessor directive?
The '#' symbol.

What does an "include" directive instruct the preprocessor to do?
It instructs the preprocessor to look for the include <file> from its set of libraries, and include it in this program.

What is the necessary function which all console C++ programs have?
int main()

Who calls that function?
Nobody, it is run automatically.

Can you declare main as void? Why use int instead?
Int is not only standard, but you can also use it for error detection as well.

Are "curly braces" optional when enclosing a function?
No.

What is the Standard Library?
A set of classes.

How do you instruct the compiler that you want to use part of the Standard Library?
You can use either 'Using namespace std;' or 'Using std::XXXx;'. Or, simply std::xxxx in lines of your code.

[Extra Credit] What's the difference between "\n" and endl?
endl clears the memory buffer on your machine.

What are the 3 ways to use a class in a namespace? Use "cout" as an example.
std::cout
using namespace std;
using std:coutl

What are the two types of comments?
//This is one type of comment.
/*This is another
type of comment*/

[Extra Credit] What is self-documenting code? Does that remove the need for comments?
Self-documenting code is simply using proper, easy-to-understand function names and variables in your code. It does not remove the need for comments, however.

Are the 3 components of a function declaration (function header)?
Return type, function name and parameters.

What do you call a function that is part of a class?
A method.

[Extra Credit]What does a compiler do with "white space?"
It ignores it.
Instead of posting a list with all the same answers again, I'm just going to answer these two. This is, because my answers were a little bit different from the others and I wonder if they are correct.

* [Extra Credit] What's the difference between "\n" and endl?
1. \n only starts a new line and endl starts a new line and clears the memory buffer
2. endl takes care of platform differences with end-line characters. (is this correct?)

* [Extra Credit]What does a compiler do with "white space?"
Depends where the white space is placed:
1.
char space = ' ';

The space is used as the value of the character.
2.
char     space = ' ';

All the extra spaces between char and space are ignored.

[Edit]And I see the extra spaces are ignored by the forum too :'([/Edit]

[Edited by - RinusMaximus on June 12, 2006 12:25:07 PM]
You can use the (code)(/code) tags with []'s instead of ()'s to tell the forum software to preserve white space.

Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Quote: Original post by Palejo
What is an interpreter?
An interpreter reads a pgm and runs it as it is being read.

Is it what the workshop book state? While being technically true, the sentence is still quite obscure. Does it give a better explaination?

Quote: Original post by Palejo
[Extra Credit]What does a compiler do with "white space?"
It ignores it.


It ignores white spaces that have no repercussion on the lexical analysis, which is quite different. As RinusMaximus, there's a difference between
char      var;

and
char var = "     "
.
Whitespaces are useful during the lexical analysis (when not enclosed between " or ') because a whitespace automatically ends a lexeme (token) and don't have any meaning by itself. It means that you can add any number of whitespace between two lexemes without changing the meaning of the lexemes.

This sounds rather dull but has a very important application in computer engineering.

There is something true about programs: they are hard to write. There is something even more true: they are even harder to read. A good use of whitespaces can really enhance the readability of the source code, that's the reason why nearly all the programmer's guidelines around the world says "code should be correctly indented and whitespaces should be used in this way".

To make sure you understood everything (not difficult), read this and tell me which program is the most understandable:

1)
#include <iostream>int main(){    int age;    std::cout << "How old are you ? ";    std::cin >> age;    std::cout << "You are " << age << " y.o" << std::endl;}


2)
#include <iostream>int main(){int age; std::cout<<"How old are you ? ";std::cin>>age;std::cout<<"You are "<<age<<" y.o"<<std::endl;}


Regards,
Maybe one of the tutors could post the correct answers to the quizzes after three weeks or so? This way we can check if we were right. It's not that important now, but for the later chapters it will probably be useful...
Quote: Original post by twoaterisn
Maybe one of the tutors could post the correct answers to the quizzes after three weeks or so? This way we can check if we were right. It's not that important now, but for the later chapters it will probably be useful...


In my idea, it would be better if the attendee post their answers first, because then the tutors will be able to explain them what are there errors and to give them hints to avoid doing the same error in the future.

Anyway, if the tutors want to post the whole answers, I suggest them to send them to jwalsh for centralization (having N tutors posting their own answers to the quizz is rather useless and confusing).

Regards,
Quote: Original post by Emmanuel Deloget
In my idea, it would be better if the attendee post their answers first, because then the tutors will be able to explain them what are there errors and to give them hints to avoid doing the same error in the future.



I agree, but after this has been done, it would be easier to check your own answers against one post. This way you don't have to read the entire thread to see which answer was given most.

This topic is closed to new replies.

Advertisement