In: Computer Science
Be able to identify valid and non-valid programmer-defined identifiers. Which header file do you need in order to use the cout and cin objects? Which header file do you need to create string variables? Be able to recognize the correct syntax to define a constant. Be able to recognize the correct syntax to store a character in a char variable. What must you have for every variable you use in a program? Program Given a program, be able to fill in missing blanks with preprocessor directives, namespace statement parts, function definition, punctuation, constant and/or variable names/types, cout/cin statements and return statements. If you can write a complete basic program at this point, you should be good to go.
In order to use the cin and cout , we need to use the namespace std in our program. The syntax to include that is
using namespace std;
In order to just create a string variable and use the basic functionality, we need to include the iostream header file. But if we want to use the complex string functions, we need to include the cstring header file. The syntax is
#include<iostream>
#include<cstring>
In order to declare a constant, we can use
const data_type variable_name = initial_value;
e.g:
const int x = 2;
In order to store a character in a char variable, we use
char ch = character;
In order to use a variable, we need to provide it a data type and assign a value to it.
#include<iostream>
#include<cstring>
using namespace std;
const int x = 2;
void fxn(int a)
{
cout<<"Argument : "<<a<<endl;
}
int main()
{
char ch = 'a';
cout<<"ch : "<<ch<<endl;
cout<<"Constant x : "<<x<<endl;
int a = 6;
// call the function
fxn(a);
return 0;
}