Jul 06, 2020, 09:41 AM

News:

Build a stunning handcrafted website with IT Acumens


Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - magesh.p

1
Hi,

Today I Learnt About How to get the file names in the folder.

And Compare the filename list with text files ( The text files contains name of the files i needed )

What ever the files missed from my list to store that filename in database name.

2
Change Text & Color when Highlighted

My Code is Below :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FontDialog1.ShowDialog()
RichTextBox1.Font = FontDialog1.Font
End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ColorDialog1.ShowDialog()
RichTextBox1.ForeColor = ColorDialog1.Color
End Sub

When I Want to change font and color in richtextbox, All Text in Textbox is Changed.

I Want  that change color and font in text that we highlight.

Help Me,

Thanks in Advance..........

3
Use the keyword struct to illustrate a primitive form of class

Code: [Select]
#include <iostream>
#include <math.h>
using namespace std;

struct math_operations {
double data_value;
 
void set_value(double ang) {
     data_value=ang;
}
double get_square(void) {
     double answer;
     answer=data_value*data_value;                         
     return (answer);
}
double get_square_root(void) {
     double answer;
     answer=sqrt(data_value);
     return (answer);
}
} math;

int main( )
{
math.set_value(35.63);

cout << "The square of the number is: "
      << math.get_square( ) << endl;
cout << "The square root of the number is: "
      << math.get_square_root( ) << endl;
return (0);
}


4
Assign one structure to another structure

Code: [Select]
#include <iostream>
using std::cout;
using std::endl;

struct Box {
  double length;
  double width;
  double height;
};

int main() {
  Box firstBox = { 80.0, 50.0, 40.0 };

  cout << firstBox.length
       << firstBox.width
       << firstBox.height
       << endl;
       
  Box secondBox = firstBox;   

  secondBox.length *= 1.1;
  secondBox.width *= 1.1;
  secondBox.height *= 1.1;

  cout << secondBox.length
       << secondBox.width
       << secondBox.height
       << endl;
 
  return 0;
}


Output

Quote
805040
885544


5
Using pointers to structure objects: delete the point

Code: [Select]
#include <iostream>
using std::cout;
using std::endl;

struct Box {
  double length;
  double width;
  double height;

  double volume();
};

double Box::volume() {
  return length * width * height;
}


int main() {
  Box aBox = { 1, 2, 3 };
  Box* pBox = &aBox;

  Box* pBox2 = new Box;
  pBox2->height = pBox->height+5.0;
  pBox2->length = pBox->length+3.0;
  pBox2->width = pBox->width+2.0;
  cout << "Volume of Box in the free store is " << pBox2->volume() << endl;

  delete pBox;
  delete pBox2;
  return 0;
}


Output
Quote
Volume of Box in the free store is 128

6
structure composition

Code: [Select]
#include <iostream>

using std::cout;
using std::endl;

#include <iostream>

struct Name {
  char firstname[80];
  char surname[80];
 
  void show();       
};

struct Date {
  int day;
  int month;
  int year;

  void show();       
};

struct Phone {
  int areacode;
  int number;

  void show();       
};

struct Person {
  Name name;
  Date birthdate;
  Phone number;

  void show();
  int age(Date& date);
};

void Name::show() {
    std::cout << firstname << " " << surname << std::endl;
}

void Date::show() {
    std::cout << month << "/" << day << "/" << year << std::endl;
}

void Phone::show() {
    std::cout << areacode << " " << number << std::endl;
}

void Person::show() {
    std::cout << std::endl;
    name.show();
    std::cout << "Brithday: ";
    birthdate.show();
    std::cout << "phone: ";
    number.show();
}

int Person::age(Date& date) {
    if(date.year <= birthdate.year)
      return 0;

    int years = date.year - birthdate.year;
   
    if((date.month>birthdate.month) || (date.month == birthdate.month && date.day>= birthdate.day))
       return years;
    else
       return --years;
}


int main() {
  Person her = {{ "L", "G" },      // Initializes Name member
                {1, 4, 1976 },     // Initializes Date member
                {999,5551234}     // Initializes Phone member
               };

  Person actress;
  actress = her;
  her.show();
  Date today = { 4, 4, 2007 };

  cout << endl << "Today is ";
  today.show();
  cout <<  endl;

  cout << "Today " << actress.name.firstname << " is "
       << actress.age(today) << " years old."
       << endl;
  return 0;
}


Output
Quote
L G
Brithday: 4/1/1976
phone: 999 5551234

Today is 4/4/2007

Today L is 31 years old.


7
Define structure to record time

Code: [Select]
#include <iostream.h>

struct Time
{
               int hh,mm,ss;
};
int main()
{
   Time t1,t2,*p;
   t1.hh=10;
   t1.mm=30;
   t1.ss=0;  //10:30:0
   t2=t1;
   t2.hh++;                             //11:30:0
   p = &t2;

   cout << "The t2 time is " << p->hh  << ":" << t2.mm << ":"<< t1.ss << endl;

   return 0;
}


Output


Quote
The t2 time is 11:30:0
8
const structure parameter

Code: [Select]
#include <iostream.h>

struct Time
{
       int hh,mm,ss;
};

void Disp1(struct Time t);
void Disp2(const Time & t);

int main()
{
       Time t1,t2,*p;
       
       t1.hh=10;
       t1.mm=30;
       t1.ss=0;
       t2=t1; 
       t2.hh++;                       
       p = &t2;
   
    cout << "The t2 time is " << p->hh  << ":" << t2.mm << ":"<< t1.ss << endl;

       Disp1(t2);
       Disp2(t2);
       
       return 0;
}

void Disp1(struct Time t)
{
       cout << "The time is " << t.hh <<":" << t.mm << ":"<< t.ss << endl;
}

void Disp2(const Time & t)
{
       cout << "The time is " << t.hh <<":" << t.mm << ":"<< t.ss << endl;
}


Output

Quote
The t2 time is 11:30:0
The time is 11:30:0
The time is 11:30:0


9
Use cin to read data for a structure

Code: [Select]
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
       struct student
       {
               int num;
           char name[20];
           float score;
       };
       struct student stu[4];
       struct student *p;
       int i,temp;
       float max;
       for(i=0;i<=4;i++)
               cin>>stu[i].num>>stu[i].name>>stu[i].score;
       for(max=stu[0].score,i=1;i<4;i++){
               if(stu[i].score>max);
               {
                       max=stu[i].score;temp=i;
               }
    }
       p=stu+temp;
       cout<<"maxmum score:";
       cout<<"NO.:"<<p->num<<"NAME:"<<p->name<<"SCORE:"<<p->score<<"\n";
}


output

Quote
maxmum score:NO.:^CTerminate batch job (Y/N)? n


10
Use memcpy to duplicate structures

Code: [Select]
#include <memory>
#include <iostream>
using namespace std;

struct mystruct
{
       int i;
       int x;
       int y;
};

int main()
{

  mystruct source,destination;

  source.i = 1;

  source.x = 2;

  source.y = 3;

  memcpy(&destination,&source,sizeof(source));

  cout << destination.i << endl;

  cout << destination.x << endl;

  cout << destination.y << endl;

  return 0;
}


Output

Quote
1
2
3


11
Structure array and structure pointer

Code: [Select]
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct st
{
       char name[20];
       long num;
       int age;
       char sex;
       float score;
};
int main()
{
       struct st student[3],*p;

       p=student;

       for(int i=0;p<student+3;p++,i++)
       {
               cout<<"Enter all data of student :["<<i<<"]\n";
               cin>>student[i].name;
           cin>>p->num;
           cin>>p->age;
           cin>>p->sex;
           cin>>p->score;
       }
       cout<<"record num name age sex score"<<"\n";
       p=student;
       for(int i=0;p<student+3;p++,i++)
               cout<<i<<p->name<<p->num<<p->age<<p->sex<<p->score<<"\n";
}


Output

Quote
Enter all data of student :[0]
1
2
3
4
Enter all data of student :[1]
E^CTerminate batch job (Y/N)? n


12
Array of structures

Code: [Select]
#include <iostream.h>
#include <stdlib.h>

#define Length 5

struct Employee {
  char title [50];
  int year;
} employee [Length];

void printemployee (Employee employee);

int main ()
{
  char buffer [50];

  for (int n=0; n<Length; n++)
  {
    cout << "Enter title: ";
    cin.getline (employee[n].title,50);
    cout << "Enter year: ";
    cin.getline (buffer,50);
    employee[n].year = atoi (buffer);
  }
  cout << "\nYou have entered these employees:\n";
  for (int n=0; n<Length; n++)
    printemployee (employee[n]);
  return 0;
}

void printemployee (Employee employee)
{
  cout << employee.title;
  cout << " (" << employee.year << ")\n";
}


Output

Quote
Enter title: Title
Enter year: 123
Enter title: Title 2
Enter year: as
Enter title: TitEnter year: ^CTerminate batch job (Y/N)? n


13
structure variables as array elements

Code: [Select]
#include <iostream> 
  using namespace std; 
  const int SIZE = 4; 

  struct part{ 
     int modelnumber;             
     int partnumber;               
     float cost;                   
  }; 
  int main(){ 
     int n; 
     part apart[SIZE];
   
     for(n=0; n<SIZE; n++){ 
        cout << endl; 
        cout << "Enter model number: "; 
        cin >> apart[n].modelnumber;
        cout << "Enter part number: "; 
        cin >> apart[n].partnumber;
        cout << "Enter cost: "; 
        cin >> apart[n].cost;       
     } 
     
     for(n=0; n<SIZE; n++) { 
        cout << "Model " << apart[n].modelnumber; 
        cout << "  Part "  << apart[n].partnumber; 
        cout << "  Cost "  << apart[n].cost << endl; 
     } 
     return 0; 
  }


14
Pass structure to a function as a pointer

Code: [Select]
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student
{
       char name[20];
       int num;
       float score[3];
};
void print(struct student *p)
{
       cout<<p->num<<"\n"<<p->name<<"\n"<<p->score[0]<<"\n"
               <<p->score[1]<<"\n"<<p->score[2]<<"\n";
       cout<<" ";
}
int main()
{
       struct student stu;
       stu.num=12345;
       strcpy(stu.name,"li li");
       stu.score[0]=67.5;
       stu.score[1]=89;
       stu.score[2]=78.6;
       print(&stu);
}


Output
Quote
12345
li li
67.5
89
78.6
"




15
Pass structure using a structure reference

Code: [Select]
#include <iostream>
using namespace std;

struct ResultStructure
{
  float base;
  float height;
  float area;
};

void f(struct ResultStructure &area);

int main ()
{
       ResultStructure myResultStructure;


    myResultStructure.base = 12;
    myResultStructure.height = 23;
    f(myResultStructure);

    cout << "The area is " << myResultStructure.area << " \n";
   return 0;
}


void f(ResultStructure &area)
{
   area.area = .5f * (area.base * area.height);
}


16
Pass structure to a function

Code: [Select]
#include <cmath>
#include <iostream>
using namespace std;

// define the structures
struct DataStructure
{
  float radius;
  double angle;
};

struct ResultStructure
{
  float area;
  double sine;
  double cosine;
  double tangent;
};

ResultStructure compute(struct DataStructure mystruct);

int main ()
{
    DataStructure input;
       ResultStructure output;

       input.radius = 3;

       input.angle = 0.8;

       output = compute(input);

    cout << " The area is "<< output.area << "\n";
       cout << " The sine of the angle is " << output.sine << "\n";
       cout << " The cosine of the angle is " << output.cosine << "\n";
    cout << " The tangent of the angle is " << output.tangent << "\n";
       return 0;
}

ResultStructure compute(struct DataStructure mystruct)
{
     ResultStructure answer;

        answer.area = pow(mystruct.radius,2);
        answer.sine = sin(mystruct.angle);
        answer.cosine = cos(mystruct.angle);
        answer.tangent = tan(mystruct.angle);

        return answer;
};



Output
Quote
The area is 9
The sine of the angle is 0.717356
The cosine of the angle is 0.696707
The tangent of the angle is 1.02964


17
Compare address

Code: [Select]
#include <ios>
#include <iostream>
#include <ostream>

struct MyStruct {
  int x;
  int y;
};

int main()
{
  MyStruct demo[10];
  std::cout << std::boolalpha;

  std::cout << (&demo[0]   < &demo[2])   << '\n';
  std::cout << (&demo[0]   == demo)      << '\n';
  std::cout << (&demo[10]  > &demo[9])   << '\n';
  std::cout << (&demo[0].x < &demo[0].y) << '\n';

}


18
Use -> for structure pointer

Code: [Select]
#include <iostream>
using namespace std;

struct account
{
   int accountnum;
   float balance;
   float interestrate;
};

int main()
{
account myaccount;
account *ptraccount;

ptraccount->balance = 1000;
       return 0;
}


19
Pointers to structures

Code: [Select]
#include <iostream.h>
#include <stdlib.h>

struct Employee {
  char title [50];
  int year;
};


int main ()
{
  char buffer[50];

  Employee aEmployee;
  Employee * pEmployee;
  pEmployee = & aEmployee;

  cout << "Enter title: ";
  cin.getline (pEmployee->title,50);
  cout << "Enter year: ";
  cin.getline (buffer,50);
  pEmployee->year = atoi (buffer);

  cout << "\nYou have entered:\n";
  cout << pEmployee->title;
  cout << " (" << pEmployee->year << ")\n";

  return 0;
}


Output
Quote
Enter title: Enter year:
You have entered:
(^CTerminate batch job (Y/N)? n


20
Define pointer for structure

Code: [Select]
#include <iostream>
using namespace std;

struct MyStructure
{
   int n;
   float f;
   float f2;
};

int main()
{
MyStructure myMyStructure;
MyStructure *ptrMyStructure;

//set the f of the structure
myMyStructure.f = 1000;

//intialize the pointer
ptrMyStructure = &myMyStructure;

//change the pointers f
ptrMyStructure->f = 2000;

//print out the structures f
cout << myMyStructure.f << "\n";

return 0;
}


21
Return structure from a function

Code: [Select]
#include <cmath>
#include <iostream>
using namespace std;

// define the structures
struct DataStructure
{
  float radius;
  double angle;
};

struct ResultStructure
{
  float area;
  double sine;
  double cosine;
  double tangent;
};

ResultStructure compute(struct DataStructure mystruct);

int main ()
{
    DataStructure input;
       ResultStructure output;

       input.radius = 3;

       input.angle = 0.8;

       output = compute(input);

    cout << " The area is "<< output.area << "\n";
       cout << " The sine of the angle is " << output.sine << "\n";
       cout << " The cosine of the angle is " << output.cosine << "\n";
    cout << " The tangent of the angle is " << output.tangent << "\n";
       return 0;
}

ResultStructure compute(struct DataStructure mystruct)
{
     ResultStructure answer;

        answer.area = pow(mystruct.radius,2);
        answer.sine = sin(mystruct.angle);
        answer.cosine = cos(mystruct.angle);
        answer.tangent = tan(mystruct.angle);

        return answer;
};


Output

Quote
The area is 9
The sine of the angle is 0.717356
The cosine of the angle is 0.696707
The tangent of the angle is 1.02964


22
writes a structure to disk and then reads it back in

Code: [Select]
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
   
struct status {
  char name[80];
  double balance;
  unsigned long account_num;
};
   
int main()
{
  struct status acc;
   
  strcpy(acc.name, "A");
  acc.balance = 1.23;
  acc.account_num = 34;
   
  ofstream outbal("balance", ios::out | ios::binary);
  if(!outbal) {
    cout << "Cannot open file.\n";
    return 1;
  }
   
  outbal.write((char *) &acc, sizeof(struct status));
  outbal.close();
   
  // now, read back;
  ifstream inbal("balance", ios::in | ios::binary);
  if(!inbal) {
    cout << "Cannot open file.\n";
    return 1;
  }
   
  inbal.read((char *) &acc, sizeof(struct status));
   
  cout << acc.name << endl;
  cout << "Account # " << acc.account_num;
  cout.precision(2);
  cout.setf(ios::fixed);
  cout << endl << "Balance: $" << acc.balance;
   
  inbal.close();
  return 0;
}


Source : java2s
23
Variables, arrays and operators

In the sample program above, i have introduced another feature of C++ without explicitly mentioning it. Variables. Variables are used to store data in it and usually waste memory space.

In C++, all Variables must be assigned a valid data type. The data types of C++ are the same as in C. Consider the following samples:

Quote
//elementary data types
bool x; //declaring a variable of type bool
char c; //declaring a variable of type char
int i;
short s;
double d;
float f;
long l;
//non-elementary data types
struct s;
class c;
enum e;
//STL special data types
24
Declaring vs Defining variables

In C++, there are 2 ways of introducing variables. The first way is called declaration of a variable. The second is called definition of a variable. The following code snippet shows the differences:

Code: [Select]
int i; //declaration of i as type int
int i = 5; //definition of variable i and assigning value 5 to it
string s;         //declaration of s as type string
s = "Hello World; //assigning "Hello World" to s
string s2 = "Hello Reader"; //definition of s as string with value "Hello Reader



Note that, when assigning values to variables, you need to make sure that the value is a valid value . This means that, when, for example, you define a variable of type int you have to make sure that the value you assign to it is an integer.

Quote
int i;
i = 5; //correct! 5 is integer

int j;
j = "Hello World" //wrong! j is not a string

double d;
d = 3.145; //correct! 3.145 is a double

int k;
k = 1.23456; //wrong! 1.23456 is not an int



If you assing wrong values to variables of another data type, the compiler will complain an error.

Defining a variable means to declare it and assign a value to it.

Declaring a variable means only to introduce it to the compiler.
25
Zenith launches new laptops


MUMBAI: Zenith Computers has announced the launch of a new range of laptops -- Admirale Plus, Presidio and Director Ultra Plus.

The new range sports reflective metal finish inspired by chrome and high-gloss surfaces. The fluid reflective screen ensures security and privacy of data with its anti-glare feature.

Announcing the launch, Raj Saraf, Chairman and Managing Director, Zenith Computers said, "The new range is especially designed to sustain the rough work environment in India."

Zenith Admirale Plus is an ideal option for business users. Based on the latest chipset from Intel, IntelGM45, it runs graphic presentations. The laptop comes with an option of processors ranging from Celeron to Intel Core2Duo.

For women, light-weight Zenith Presidio is a preferable option. It has a glossy piano finish in black and comes with a biometric finger print reader for secured computing. It is based on the 965 chipset from Intel, runs on Windows Vista Business and offers additional features like Bluetooth, 2 megapixel camera, Giga LAN, DVD writer and memory card reader.

Zenith Director Plus Ultra draws inspiration from stylish sports cars. Built with a magnesium alloy, the laptop is protected against bending caused due to any kind of impact and accidental drops. It has a dedicated 512mb graphics card with c2d processor and Intel pm45 motherboard. The laptop also has an integrated 2 megapixel camera and wireless card.

Source : indiatimes
IT Acumens Web Designing Chennai | GinGly :: Build your Personal Website | CineBuzz :: Cinema News | My Kids Diary :: Kids Memories Writing :: Book Website @ 349 Rs monthly
Copyright 2005 - 2020 :: IT Acumens :: All Rights Reserved. :: Sitemap
ITAcumens Discussion Forum with 2 lakhs post running for 15 years - Powered by IT Acumens Dedicated Server