Saturday, 25 February 2012

Dynamic Array (Example)


#include <iostream>
using namespace std;
int main()
{
                int* arr=NULL;
                int size;
                cout<<"How many number u want?";
                cin>>size;
                int sum=0;
                arr=new int[size];
                for(int i=0;i<size;i++)
                {
                                cout<<"Enter number :";
                                cin>>arr[i];
                }
                for(i=0;i<size;i++)
                {
                                sum=sum+arr[i];
                }
                cout<<sum;       
                return 0;
}

Binery File - Read (With Structures)


#include <iostream>
#include <fstream>
using namespace std;
int const SIZE=50;
struct student
{
                char name[SIZE];
                int roll;
                char clas[SIZE];
};
int main()
{
                student std1;
                ifstream file("D://Ali.txt",ios::binary);
                if(!file)
                {
                                cout<<"File is not located"<<endl;
                }
                else
                {
                                file.read((char*)&std1,sizeof(std1));
                                cout<<"Name :"<<std1.name<<"\nRoll No :"<<std1.roll<<"\nClass :"<<std1.clas<<endl;
                }
                file.close();
                cout<<"File is Read"<<endl;
                return 0;
}

Binery File - Write (With Structures)


#include <iostream>
#include <fstream>
using namespace std;
int const SIZE=50;
struct student
{
                char name[SIZE];
                int roll;
                char clas[SIZE];
};
int main()
{
                student std1;
                ofstream file("D://Ali.txt",ios::binary);
                cout<<"Enter name :";
                cin>>std1.name;
                cout<<"Enter Roll No :";
                cin>>std1.roll;
                cout<<"Enter Class :";
                cin>>std1.clas; 
                file.write((char*)&std1,sizeof(std1));
                cout<<"File is write"<<endl;
                file.close();
                return 0;
}

Binery File - Read (simple Program)


#include <iostream>
#include <fstream>
using namespace std;
int main()
{
                char name;
                ifstream file("D://Ali.txt",ios::binary);
                while(!file.eof() && name!='\0')
                {
                                file.read((char*)&name,sizeof(name));
                                cout<<name;
                }
                cout<<endl;
                cout<<"File is Read"<<endl;
                file.close();
                return 0;
}

Binery File - Write (Simple Program)


#include <iostream>
#include <fstream>
using namespace std;
int main()
{
                char name[50];
                ofstream file("D://Ali.txt",ios::binary);
                cout<<"Enter name :";
                cin.get(name,50);
                file.write((char*)&name,sizeof(name));
                cout<<"File is write"<<endl;
                file.close();
                return 0;
}

Friday, 27 January 2012

Arrays in the form of different Parameters



#include<iostream>
using namespace std;
int show_array(int arr[],int size,int *ptreven,int *ptrodd)
{ 
 for(int j=0;j<size;j++)
 {
  if(arr[j]%2==0)
   *ptreven=*ptreven+arr[j];
  else
   *ptrodd=*ptrodd+arr[j];
 }
 return (*ptreven+*ptrodd);
}

int main()
{
 //variables
 int const SIZE=10;
 int arr[SIZE];
 int sumeven=0,sumodd=0,totalsum=0; 
 
 //Calling
 for(int i=0;i<SIZE;i++)
 {
  cout<<"Enter number At "<<i<<" index :";
  cin>>arr[i];
 }
 totalsum=show_array(arr,SIZE,&sumeven,&sumodd);
 cout<<"Sum of even elements in array :"<<sumeven<<endl;
 cout<<"Sum of odd elements in array :"<<sumodd<<endl;
 cout<<"Sum of All elements in array :"<<totalsum<<endl;
 return 0;
}

Saturday, 21 January 2012

Here is the 15th lecture of C++ programming
(2D Array).
Please click this link below and Attend an important Lecture 

Lecture 15
Here is the 14th lecture of C++ programming
(Inheritance).
Please click this link below and Attend an important Lecture
Lecture 14
Here is the 13rd lecture of C++ programming
(Constructors).
Please click this link below and Attend an important Lecture
 

Lecture 13
Here is the 12nd lecture of C++ programming
(Classes And Object 2).
Please click this link below and Attend an important Lecture
 

Lecture 12
Here is the 11st lecture of C++ programming
(Classes And Object).
Please click this link below and Attend an important Lecture

Lecture 11
Here is the 10th lecture of C++ programming
(Recuression).
Please click this link below and Attend an important Lecture
 

Lecture 10
Here is the 9th lecture of C++ programming
(Function Overloading).
Please click this link below and Attend an important Lecture
 
Lecture 9
Here is the 8th lecture of C++ programming
(Function).
Please click this link below and Attend an important Lecture

Lecture 8
Here is the 7th lecture of C++ programming
(Pointer).
Please click this link below and Attend an important Lecture. 
Lecture 7