C++ Q and A

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 5

List the steps in processing c++ program

• Determine the type of link required.

• Declare a stream for of link.

• Attach the file to the stream.

• Now process as required.

• Close the file-link with stream.


The two main types of comments in c++
The single line comment starts with // Multi line comment is used to comment
(double forward slashes). multiple lines of code. It is surrounded by
forward slash and asterisk (/∗ ..... ∗/). 
#include <iostream>  
#include <iostream>  
using namespace std;   using namespace std;  
int main()   int main()  
{   {  
 int x = 11; // x is a variable       /* declare and   print variable in C+
 cout<<x<<"\n";          +. */   
 int x = 35;     
}  
 cout<<x<<"\n";         
}  
Name and describe integral data types when naming variables in c++

• int - stores integers e.g. 1,2,100


• double - stores floating point numbers e.g. 1.2, 0.5
• char - stores single characters, such as 'a' or 'B'. ...
• string - stores text e.g. "Hello World".
• bool - stores values with two states: true or false.
Rules for naming a variable

• The first character must be a letter or underscore.


• Blank spaces cannot be used in variable names.
• Special characters like #, $ are not allowed.
• C++ keywords cannot be used as variable names.
• Variable names are case-sensitive.
C++ Program to Convert Temperature from Celsius to Fahrenheit Scale
#include <iostream>
using namespace std;
  int main()
{
    float fahren, celsius;
    cout << "Enter the temperature in celsius\n";
    cin >> celsius;
       fahren =(9.0/5.0) * celsius + 32;
    cout << celsius <<"Centigrade is equal to " << fahren <<"Fahrenheit";    
    return 0;
}

You might also like