C,C++/JAVA/BASH/ASM ARENA

वह प्रदीप जो दीख रहा है झिलमिल दूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है चिन्गारी बन गयी लहू की बून्द गिरी जो पग से चमक रहे पीछे मुड देखो चरण-चिनह जगमग से बाकी होश तभी तक, जब तक जलता तूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है अपनी हड्डी की मशाल से हृदय चीरते तम का, सारी रात चले तुम दुख झेलते कुलिश का। एक खेय है शेष, किसी विध पार उसे कर जाओ; वह देखो, उस पार चमकता है मन्दिर प्रियतम का। आकर इतना पास फिरे, वह सच्चा शूर नहीं है; थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है। दिशा दीप्त हो उठी प्राप्त कर पुण्य-प्रकाश तुम्हारा, लिखा जा चुका अनल-अक्षरों में इतिहास तुम्हारा। जिस मिट्टी ने लहू पिया, वह फूल खिलाएगी ही, अम्बर पर घन बन छाएगा ही उच्छ्वास तुम्हारा। और अधिक ले जाँच, देवता इतन क्रूर नहीं है। थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है।

overloading less than(”) operator April 28, 2010

Filed under: C,C++ Programs,OOPS — whoami @ 21:38
Tags: , ,

//Write a program to overload the operator < and >such that it compares two strings
//and returns the appropriate result .the string should be read and printed using the
//overlloaded stream operator

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

class A{
 public:
 char s1[100],s2[100];

 public:
 int operator <(A &obj){

 int n=strcmp(s1,obj.s2);
 if(n<0) return 1;
 else return 0;
 }

 int operator >(A &obj){

 int n=strcmp(s1,obj.s2);
 if(n>0) return 1;
 else return 0;
 }

 friend istream& operator >> (istream &in,A &obj){

 in>>obj.s1;
 in>>obj.s2;
 return in;
 }
 friend ostream&  operator << (ostream &out,int n){
 out<<n;
 return out;
 }
};

int main()
{
 A a;

 cin>>a;


 cout<<(a<a)<<endl;
 cout<<(a>a)<<endl;

return 0;
}

Advertisements
 

friend function implemented

Filed under: C++ Programs,OOPS,Uncategorized — whoami @ 18:43
Tags: ,

//Write a program using friend function which will add two distances
//stored in two different classes.The first class holds the distance
// in m & cm and the second class holds the distance in feet & inch

#include<iostream>
using namespace std;

class B;
class A{
 float m,cm,res;
 public:
 A():m(20.0),cm(2.0){}
 void fun(B obj);
};

class B{
 float feet,inch;
 public:
 B():feet(9),inch(3){}
 friend void A::fun(B obj);
};
void A::fun(B obj){
 res=m*100.0+cm+obj.feet*12.0*2.54+obj.inch*2.54;
 res=res/100;

 cout<<res<<"metre\n";
}


int main()
{
 A a;
 B b;
 a.fun(b);

 return 0;
}

 

TopCoder SRM 147 Div2 February 13, 2010

Filed under: C,C++ Programs,OOPS,Top Coder,TOPCODER — whoami @ 10:21
Tags: , ,

TopCoder SRM 147 Div2
C++
–SUBMITTED–[149 points]

#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
using namespace std;

class CCipher{

   public:
       string decode(string cipherText,int shift){
         for(int i=0;cipherText[i]!='\0';i++)
            cipherText[i]='A'+(cipherText[i]-'A'+26-shift)%26;
          return cipherText;
        }
};

/*int main()
{
 CCipher c;
 string s=c.decode("VQREQFGT",2);
 cout<<s<<endl;

return 0;
}
*/

 

TopCoder SRM 262 – DivToZero C++ February 12, 2010

Filed under: C,C++ Programs,OOPS,Top Coder — whoami @ 21:29
Tags: , ,

TopCoder Single Round Match 262 Round 1 – Division II, Level One

–AC–
c++
The format in which i submitte it :-

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
class DivToZero{
   int i,j;
   char s[20];
   public:
      string lastTwo(int num,int factor){
        if(num%factor==0){
              j=num%100;
              if(j<10)
              sprintf(s,"0%d",j);
              else
              sprintf(s,"%d",j);
              //cout<<j<<endl; 
              return s;
             }
         else{
             
             num=num/100;
             num=num*100;
             for(i=num;;i++)
             {
               if(i%factor==0)
                  break;
             }
              j=i%100;
              //cout<<num<<endl;
             if(j<10)
             sprintf(s,"0%d",j);
             else
             sprintf(s,"%d",j);
            return s;
          }
       }
};





here is a snapshot of the arena
TopCoder 1st Submission
The format in which i tested in g++ on my system for each of test case is below

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
class DivToZero{
   int i,j;
   char s[20];
   public:
      string lastTwo(int num,int factor){
        if(num%factor==0){
              j=num%100;
              if(j<10)
              sprintf(s,"0%d",j);
              else
              sprintf(s,"%d",j);
              //cout<<j<<endl; 
              return s;
             }
         else{
             
             num=num/100;
             num=num*100;
             for(i=num;;i++)
             {
               if(i%factor==0)
                  break;
             }
              j=i%100;
              //cout<<num<<endl;
             if(j<10)
             sprintf(s,"0%d",j);
             else
             sprintf(s,"%d",j);
            return s;
          }
       }
};


int main()
{
  DivToZero a;
  string p=a.lastTwo(32442,99);
  cout<<p<<endl;

return 0;
}
  

 

TopCoder Arena launching in fedora(linux)

Filed under: C++ Programs,OOPS,TOPCODER — whoami @ 20:10
Tags:

Today i launched Topcoder arena in feodra. To do this just save the tocoderapplet file and then open it with firefox and then enter option …/../jawas which is located in java folder or jre folder of java……………

Now i will start doing problems over here also. One important thing about topcoder is that it doesnot use ” main ” function .However method has to be defined public.

TopCoder!!!!!!!!!!!!!

 

Nested Friends c++

Filed under: C,C++ Programs,OOPS — whoami @ 08:30
Tags: , ,

[..from Eckel c++]
Making a structure(or class) nested doesnot automatically give it access to private members.To accomplish this,we must follow a particular form, first declare (without defining ) the nested structure ,then declare it as s friend ,and finally define the structure.The structure definition must be separate from the friend declaration ,otherwise it would be seen by the compiler as a non-member.

(more…)

 

Friend c++ demonstration

Filed under: C,C++ Programs,OOPS — whoami @ 07:40
Tags: , ,

[..from C++ Eckel]

//Friend -demonstration
#include<iostream>
using namespace std;

struct X;

struct Y{
   void f(X*);
};

struct X{
   private:
     int i;
   public:
     void initialize();
     friend void g(X*,int);//global friend
     friend void Y::f(X*);//struct member friend
     friend struct Z; //entire struct is a friend
     friend void h();
};

(more…)