1. Introduction c++ First programming
The online compiler use in this course is GDB online.
You want to learn more in c++ than chack out the W3school.com
Some library function in c++ visit this website
Our first code
/* Hellow world code */
#include <iostream>
using namespace std;
int main (){
cout<<"I'm Md Nakibul Islam "<<endl;
cout<<"I'm from Bangladesh"<<endl;
cout<<"Feni";
return 0;
}
2. Data Types & Variables
Data Type | Size | |
---|---|---|
int | 4 bytes | |
float | 4 bytes | |
double | 8 bytes | |
char | 1 byte |
Class Code
#include <iostream>
using namespace std;
int main()
{
int num = 40 , I = 70;
float k = 10.5 , L = 50;
double H = 4.2548;
char w = 'a';
string T = "My name is Nakib";
num = I;
cout<<num<<endl;
cout<<k<<endl;
cout<<L<<endl;
cout<<I<<endl;
cout<<H<<endl;
cout<<w<<endl;
cout<<T;
return 0;
}
3. User Input & Output
Class Code
#include <iostream>
using namespace std;
int main()
{
string x,k;
cout<<"Enter Your Name : ";
cin>>x;
cout<<"Enter your Friend Name :";
cin>>k;
cout<<"Your Name is : "<<x<<endl;
cout<<"your Friend Name is :"<<k;
return 0;
}
4. If else & else if
Class Code 1
#include <iostream>
using namespace std;
int main()
{
int x;
cout<<"Enter a Number : ";
cin>>x;
if(x>5){
cout<<"Hi";
}
else {
cout<<"Goodbye";
}
return 0;
}
Class Code 2
#include <iostream>
using namespace std;
int main()
{
int x;
cout<<"Enter a Number : ";
cin>>x;
if(x>=5){
cout<<"Hi";
}
else {
cout<<"Goodbye";
}
return 0;
}
Class Code 3 #include <iostream>
using namespace std;
int main()
{
int x;
cout<<"Enter a Number : ";
cin>>x;
if(x%2==0){
cout<<"Hi";
}
else {
cout<<"Goodbye";
}
return 0;
}
Class Code 4
#include <iostream>
using namespace std;
int main()
{
int x;
cout<<"Enter a Number : ";
cin>>x;
if((x%2==0) && (x%5==0)){
cout<<"Hi";
}
else {
cout<<"Goodbye";
}
return 0;
}
Class Code 5 #include <iostream>
using namespace std;
int main()
{
int x;
cout<<"Enter a Number : ";
cin>>x;
if((x%2==0) || (x%5==0)){
cout<<"Hi";
}
else {
cout<<"Goodbye";
}
return 0;
}
lass Code 6
#include <iostream>
using namespace std;
int main()
{
int x;
cout<<"1.you"<<endl;
cout<<"2.My"<<endl;
cout<<"3.Hello"<<endl;
cout<<"4.sorry"<<endl;
cout<<"Enter a option(1-4) : ";
cin>>x;
if(x==1){
cout<<"1.you";
}
else if(x==2){
cout<<"2.My";
}
else if(x==3){
cout<<"3.Hello";
}
else if(x==4){
cout<<"4.sorry";
}
return 0;
}
5. Loop
lass Code 1
#include <iostream>
using namespace std;
int main()
{
int i;
for(i=0; i<5; i=i+1){
cout<<i<<" Hi"<<endl;
}
return 0;
}
lass Code 2
#include <iostream>
using namespace std;
int main()
{
int i;
for(i=5; i>0; i=i-1){
cout<<i<<" Hi"<<endl;
}
return 0;
}
lass Code 3
#include <iostream>
using namespace std;
int main()
{
int i=0;
while(i<5){
cout<<i<<" Hi"<<endl;
i=i+1;
}
return 0;
}
lass Code 4
#include <iostream>
using namespace std;
int main()
{
int i=0 , k;
cout<<"Enter a Number : ";
cin>>k;
while(i<k){
cout<<i<<" Hi"<<endl;
i=i+1;
}
return 0;
}
6. Array
lass Code 1
#include <iostream>
using namespace std;
int main()
{
int i, x[5] = {10,20,30,40,50};
for(i=0; i<5; i=i+1){
cout<<x[i]<<endl; //i=0,1,2,3,4
}
return 0;
}
lass Code 2
#include <iostream>
using namespace std;
int main()
{
int i, x[5] = {10,20,30,40,50} , k[5] = {1,2,3,4,5} , l[5]={0};
for(i=0; i<5; i=i+1){
l[i] = x[i] + k[i];
cout<<" "<<l[i];
}
return 0;
lass Code 3
#include <iostream>
using namespace std;
int main(){
int x[3][2]={{10,20},{30,40},{50,60}} , i ,j;
for(i=0; i<3; i=i+1){ //i for row and j for clom // i=0,1,2,3
for(j=0; j<2; j=j+1){ // j=0,1,2,0,1,2,0,1,2
cout<<" "<<x[i][j];
}
cout<<endl;
}
return 0;
}
}
7. Libray Function
lass Code
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
int x;
srand(time(0));
x = rand()%10+1;
cout<<x;
return 0;
}
No comments:
Post a Comment