90 likes | 103 Views
C++. Demonstration. Fundamental of C++. int main() with return 0 void main() without return 0 File name must be .cpp <br> is used between “<br>” <br> means new line endl = End line is used after output redirector <<endl;. Note. #include <iostream.h> #include is pre-processor directive
E N D
C++ Demonstration
Fundamental of C++ • int main() with return 0 • void main() without return 0 • File name must be .cpp • \n is used between “\n” \n means new line • endl = End line is used after output redirector <<endl;
Note • #include <iostream.h> • #include is pre-processor directive • iostream.h = input output stream (stream refers to the flow of input or output) • << output redirection operator it has to be used after cout object • >> input indirection it is used after cin for example cin>>a; • #include<iostream> using namespace std; (A new standard of C++)
Comment • Line comment \\ • \\ bc stands for beginning counter • Block comment \*comment here*\ \* *\ • Multiple lines of comments between \* and *\
Sample program – hidden characters #include <iostream> using namespace std; int main(){ char University[] = “Phnom Penh International University";//Need to retype char Faculty[]("Computer sciences"); //Need to delete extra space cout << "Welcome to the Student Orientation Program.\n"; cout << "For your studies, we have selected:\n"; cout << "Institution: " << University << "\n"; cout << "Faculty: " << Faculty << "\n"; return 0; }
Celsius to Fahrenheit • c = 5 (f-32)/9 • 9c/5=f-32 • f= 9c/5+32
Palindrome - number • P = 1331, r=0 • When I = 1 • Num = 1331 mod 10 = 1 • P = p/10 = 133 • R= num + (r*10) = 1 • I = 2 • Num=133 mod 10 = 3 • P = p/10=13 • R=num+(r*10) = 13 • i=3 • Num=13 mod 10 = 3 • P=p/10=13/10=1 • R=num+(r*10)=133 • i=4 • Num=1mod 10 = 1 • P=p/10=1/10=0 • R=num+(r*10)=1331
Matrix Product A B C