Explain our code so far in Triple X!

The preprocessor directive we load in Triple X is used to load the iostream library. This presumably allows us to use code more efficiently. We don’t need to write all the code for outputting a string to the terminal each time, we can just use the cout function included in the iostream library. The cout function will do all the hardwork and our code becomes one simple line in Triple X.

The main() function is the entry point for our Triple X program. Without this function our program does not compile and can not be run. The return statement returns the status of our application once it has been run, a return value of anything other than 0 would suggest an error had occurred within our program at runtime.

An expression is a line of code that is performing some computation such as a+b or printing something to the terminal. A declaration is where we initialise a variable, or constant, for example: int a=4. Both expressions and delcarations are defined as statements with the ; at the end of the line.

  1. I think that a preprocessor directive is, essentially, a library of codes and functions that we add on to our own code in order to use certain commands.

  2. A main function allows us to output expression statements and declarations, and it is seen as the core of your code, where most functions pass through.

  3. A return statement is placed at the very end of the function, and it signals exiting the code.

  4. So far, in our code, it contains std::cout statements, so we are outputing text to the console. We are also declaring variables and outputing them using std::cout << x << endl;

It takes previously built code organized into a library and runs it, giving us more options of functions to use in our code.

The main function serves as a capsule of our code that, when called by the program, will do the operations described in the code and may or may not return something.

The return statement closes the function and returns nothing, which is signaled by 0.

Our expression statement prints the text of the game, giving the player insight on what the game is about, and also prints the result from two operations, the sum of the variables and their product.

The declaration statements creates 5 variables and assigns each their own value, and tells the computer that their value is not to be changed with the const command.

What does our preprocessor directive do?

informs the compiler it needs to import the necessary libraries for the input and output stream of C++ to function.

Why do we have a main function? What does it’s return statement do?

The main function is what the tells the compiler what needs to happen during the course of the program. The return statement has to do with the return type Int at the beginning of the main function. The return type tells the compiler that I am expecting something to be returned of this variable type before this method or function can end. The return statement in the main function is generally there to explain how the operation performed. if it returns 0 there were no errors, other returns represent error codes.

Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.

Our expressions are informing the user of the narrative line by line and outputting the relevant variables to solve the puzzle. Our declarations are the initialization of the variables we intend to use for the puzzle. Currently they are set as constants and can’t be altered outside there initialization.

  1. it’s a standalone code, written by another person, that is included and read before our code
  2. main - our code
  3. our expression statements explain the game to the player
  4. our declaration statements explain the game to the to the compiler? i mean, without them, the compiler wouldn’t know what to do, so…
  5. return 0; with that, i assume, the code tells the compiler to return to the line 0…
  • preprocessor Directive #include <iostream> includes Headerfile iostream before following code
  • main function is the function to start the program, and is necessary in every program
  • first expressoin statements are introduction to the program and explain what it does
  • declaration statements declares variables which are used later
  • 2nd expression statements print the declared variables on the screen
  • Return Statement terminates the program, 0 is the exit code

In out program, the very first line i.e., #include <iostream> is a preprocessor directive in which they were summon by compiler to process before our program compilation.

Then we have int main() function which we can precise as the entry point of the program. I mean when compiler compiles and run our program it will first look main() function and so it s the entry point of our program. It also have return statement in the program which execute our program function. It is written in main() function then it will terminate our program. Also return statement can return a value to the calling function.

And inside main() function we have Declaration statements and Expression statements. Declaration statements means that defines a variable to hold some value or character and expression statements means that have both value and type.

The preprocessor directive is calling in an outside library to be used in our code.

The main function is necessary for the program to run. The return statement says that the function doesn’t return anything after running.

The expression statement is the output.

Declaration statement is where variables are declared.

Gives instruction to the compiler to include library with another codes.

Because C++ would not run without main function.

We briefly explained the story and what is the pupose of our little game. Then we declared variables (a, b , c, sum and product) and printed out the sum and product values.

Gives us a feedback on whether there are any errors. 0 indicate no errors, other than 0 means error.

The preprocessor directive is telling the compiler to process the code “to look at it” before compilation.

The main function is the driver to run all the code for output after compilation.

The return statement is telling the program that it has finished successfully.

We so far have declared integer variables set in a constant state, so that we protect ourselves from changing what we have initialized in the first place. Then we created a new set of statements to find the sum and product totals. Finally, we called our variables to be outputted on the terminal and separating them on a new line with “endl”

The end.

The Preprocessor directives is basically a directory of information or library’s, that start with #, that the compiler will run before it processes any of the other information.

Why do we have a main function? the main function, just like any other function, has a return value but the main function is run by the operating system.

Explain our expression and declaration statement that we have written so far, to summarise what our program is doing. Expression statements are generally used to process information. While decleration statements hold and controls variables.

What does it’s return statement do? It’s basically a tiny electric accountant making sure your books are balanced.

What does our preprocessor directive do?

Brings the existing functionality from “iostream” into our program.

Why do we have a main function? What does its return statement do?

The main function delegates everything that will run inside of our program. The return statement (with a value of 0) lets the compiler know that the main function executed successfully and the program can exit out.

Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.

The main function begins by sending two strings out to the terminal, each given their own line. Then it declares integer variables A, B, and C, giving them unique numerical values. The next integer variables, Sum and Product, receive their declared values with mathematical calculations of A, B, and C. (A + B + C, and A * B * C, respectively). Finally, the main function sends the value of Sum and the value of Product to the terminal, each given their own line, and executes the return statement.

okay!

The Preprocessor Directive allows us to use code from outside of our current code

the main function runs the whole code when called
the first set of expression statements set up the info of the game

the declaration statements declare variables used in the expression statements

the second set of expression statements print the declared variables in the console

the return statement returns the console to null

1 Like

What does our preprocessor directive do?

ans: brings code from another library which has been pre coded by others.

Why do we have a main function? What does it’s return statement do?

ans: the main function is the basic function which is needed for any C++ program. The project will not run if the int main() function is not there. The return statements , if returned 0 , then it means the code is successful.

Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.

Preprocessor directive #include is used to include basic library/header function of I/O in the program so we don’t need to rewrite I/O code just used it. Main function is staring point of the program compiler searches for it and starts compiling in it. Return statement used on the end of code which means we don’t want to return anything to the compiler. In the last, expression and declaration statement plays an important role while making the mighty Triple X. Expression statements used for display and declaration statement used for variable declaration & initialization.

The Preprocessor Directive loads code that someone else wrote so that you can use it in your own code without writing it from scratch.

The Main function is the main portion of the code that compiles everything together and processes what you want the code to do.

Expression statements are for taking different parts of the program and expressing them in a certain format? I am not too sure on this one though.

Declaration statements are for defining the terms of the program.

The Return statement tells the program you are done?

Preprocessor Directive: An instruction to the compiler before the actual compilation of code begins.
Main function: The starting point of a program.
Expression Statement: A statement that ends with a semi-colon.
Declaration Statement: Introduce identifiers into the program.
Return statement: Ends the function.

*Preprocessor Directive- enters code from another library
*Main Function- holds all of the code in a program
*Return statement- the end of the main function

  • Expressions statement- a statement that ends with a semicolon
  • Declaration statement- statements that declare something

What does our preprocessor directive do?
Ans - Pre-processor directive tell the compiler to add header file in our code before compiling our code.

Why do we have a main function? What does it’s return statement do?
Ans - Main function is starting execution of our program. All the functions has the return type like int, float, double if we forget to write return type its throw some error.

Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.
Ans- Our expression statement is display on terminal with the help of iostream. when we delcared some variable in our code that expression is called declaration expressions.

What does our preprocessor directive do?
It is processed before our code is compiled. It starts with a hashtag followed by the action we want the compiler to perform such as ‘include’ which enables us to use existing library code for example input output stream ‘iostream’.

Why do we have a main function? What does it’s return statement do?

The main function is the body of our code, it contains expression statements and declaration statements, it is also the place where functions are being called and passed a value too. It tells the compiler that it ran successfully by returning a 0.

Explain our expression and declaration statement that we have written so far, to summarize what our program is doing.
An expression statement is an expression that ends with a semicolon such as outputting to the terminal or changing the value of a variable…
Where as a declaration statement is declaring a new instant of something such as declaring an integer variable x.
In our code:

  • We printed the mission
  • declared some variables and initialized them
  • printed the sum and product

Privacy & Terms