Showing posts with label Array of Constructor Parameter. Show all posts
Showing posts with label Array of Constructor Parameter. Show all posts

Wednesday, 31 October 2012

Program Of Increament and Decreament, Uniary Operator In C++


#include<iostream.h>
#include<conio.h>

main()

{

clrscr();

int a,b,c,d,e,f;


a=10;

                           b=++a;         //a=11 , b=11
                           c=a--;           //c=11 , a=10
                       d=--a;           //a=9 , d=9 
                       e=--a;           //e=8 , a=8
                       f=a++;         // a=8 , f=9
        
cout<<"\n a="<<a;
        
cout<<"\n b="<<b;
       
 cout<<"\n c="<<c;
       
       
      
  
 getch();
}

Friday, 26 October 2012

Program Of Data Entry Or Add Records Using C

#include<stdio.h> 
#include<conio.h>
 
#include<string.h>
 
{
 

char name[40];
 

int age;
 

float bs;
 

};
 

main()
 

{
 

clrscr();
 

FILE *fp;
 
struct emp e;
 
char s[80];
 
char another='y';
 
if(fp==NULL)
 
{
 
printf("Can't Open File");
 
exit(1);
 
}
 
printf("\n File  TEXT Is=");
 
printf("\n");
 
printf("\n Enter Name,AGE,Basic salary");
 
scanf("%s",e.name);
 
scanf("%d",&e.age);
 
scanf("%f",&e.bs);
 
printf("Add Another Record(y/n)");
 
another=getche();
 
}
 
fclose(fp);
 
getch();
 
}

Sunday, 6 May 2012

Program Of Opening a File In C++

#include<iostream.h>
#include<conio.h>
main()

{

    clrscr();

    char FirstName[30], LastName[30];

    int Age;

    char FileName[20];

    cout << "Enter First Name: ";

    cin >> FirstName;

    cout << "Enter Last Name:  ";

    cin >> LastName;

    cout << "Enter Age ";

    cin >> Age;

    cout << "\nEnter the name of the file you want to create: ";

    cin >> FileName;


     Students << FirstName << "\n" << LastName << "\n" << Age;
  
    getch();

}

Saturday, 5 May 2012

Program Of Conversion Between Basic to Object In C++

#include<iostream.h>
#include<conio.h>
class add
{
int a;
public:
add(int x)
{
a=x;
}

{
return a;
}

void show()
{
cout<<"a is="<<a;
}
};
main()
{
clrscr();
int r;
add a1(4);
a1.show();
                    r=a1;           // Basic to Object
cout<<"\n Value of r="<<r;
getch();
}

Wednesday, 2 May 2012

Program Of Fibonacci Series In c

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
a=0;
b=1;
printf("Enter Limit=");
scanf(" %d",&n);
printf("%d",a);
printf("  %d",b);
{
 c=a+b;
 a=b;
 b=c;
}

getch();
}

Saturday, 28 January 2012

Program Of Array of Constructor Parameter In C++


#include<iostream.h>
#include<conio.h>
class add
{
private:
int x,y;           // Data Member
public:
add(int p,int q)   // Default Parameter Constructor
{
x=p;
y=q;
}
void display()
{
int r;
r=x+y;
cout<<"\n NAswer="<<r;
}


};
main()
{
clrscr();
int i;
add a[3]={add(2,4),add(5,7),add(9,10)};
for(i=0;i<3;i++)
{
a[i].display();
}
getch();
}

---------------------------------------------------------------

If you have an array of objects, the only constructor that can be called on each object is the default constructor. You cannot use a non default constructor to construct arrays of objects. So if we reuse the phonerec declaration from the previous page: phonerec() : name("Me"),phonenunber("555-1000") {}
and declare an array of three phonerecs, phonerec subscribers[3];
then this will call the default constructor three times, once on each object and set the name field of each to "Me" etc.

The example below uses an initializer list that constructs each object in an array of 10 objects, and calls a function to set each object to have a different id value. After the array has been constructed, A[0]has an id of 0, A[1] an id of 1 etc. #include <string> using namespace std; int x=0; int getX() { return x++; } class a { public: int b; int id; string s; a() : id(getX()), b(5), s("value2") { } }; void main() { a A[10]; } a A[10];
This can also be done by using a static data member of a class. We'll see those in a future lesson.



Thursday, 19 January 2012

Program Of Array of Constructor Parameter In C++


#include<iostream.h>
#include<conio.h>
class add
{
private:
int x,y;           // Data Member
public:
add(int p,int q)   // Default Parameter Constructor
{
x=p;
y=q;
}
void display()
{
int r;
r=x+y;
cout<<"\n NAswer="<<r;
}


};
main()
{
clrscr();
int i;
add a[3]={add(2,4),add(5,7),add(9,10)};
for(i=0;i<3;i++)
{
a[i].display();
}
getch();
}

------------------------------------------------------------------------------------

  In this section we consider the Array<T> class constructor which takes two numeric arguments of type unsigned int. The definition of this constructor is given in Program gif. Given argument values m and n, the constructor first allocates an array of n elements of type T using operator new, and then sets the length field to n and the base field to m. The running time is a constant plus the time do the array allocation.