Wednesday 2 October 2013

Need help for operators << and >>

Can anybody explain--please..

Usually overloading operators << and >> should return ostream by reference. But in our project why does it return console by reference??

Monday 23 September 2013

Following is my solution for basicmath problem.
I am still not satisfied with the efficiency of the code but happy that I  tried by myself and could do it.


#include<iostream>
#include <stdlib.h>
using namespace std;



int main(int argc , char* argv[])
{

if (argc < 4){
cout<<"<Number> <+-x/> <Number> <Enter>" << endl;
}
else if(argc == 4)
{
int i = 1;
int j = 0;
int count=0;
int firstArg;
int thirdArg;
while(argv[i])
{
if(i != 2)//check if first and third commandline arguements have digits only.
{
while(!isdigit(argv[i][j]) && argv[i][j])
{
count++;//to count characters except digits
j++;//count digits
}

}
i++;//loop for frist and second arguements
}
if(count > 0)//if there are other characters other than digits
{
cout<<"<Number> <+-x/> <Number> <Enter>" << endl;
}
else if(*argv[2] == '+')
{
firstArg = atof(argv[1]);
thirdArg = atof(argv[3]);
cout<< firstArg + thirdArg << endl;
}
else if(*argv[2] == '-')
{
firstArg = atof(argv[1]);
thirdArg = atof(argv[3]);
cout<< firstArg - thirdArg << endl;
}
else if(*argv[2] == 'x')
{
firstArg = atof(argv[1]);
thirdArg = atof(argv[3]);
cout<< firstArg * thirdArg << endl;
}
else if(*argv[2] == '/')
{
firstArg = atof(argv[1]);
thirdArg = atof(argv[3]);
cout<< firstArg / thirdArg << endl;
}
}



}
////steps
///*
//-first determine how many arguments are there?
//if there are less than four args then print right format
//if there are 4 args in total than
//check first and third arguments contain numbers only
//if not print right format
//if yes then check second argument contain one of these(+-x/)
//if not print right format
//if yes then convert first and third arguements to integer
//at last do the calculations

Monday 3 June 2013

segmentation fault ..... in function const char nstrcat( char* des,... )

const char* nstrcat(char* des, ...){
      
   char* s;
   va_list vargs;
   va_start(vargs, des);

    while(s = va_arg(vargs, char*))
    {
        for(; *s; s++)
       {
          *des = *s;
            des++;
       }
    }
        *des = 0;
        va_end(vargs);
        return des;
}


Can anybody help to solve this?????

Monday 27 May 2013


Solution Of  int AscToInt(const char* num)

int AscToInt(const char *num){
    int intNum = 0;
    int curDigit = 0;
    int minus = 1;

    if(*num == '-')
    {
        minus = -1;
        num++;
    }
   
    int len = strlen(num) - 1;

    for(int i = 0;i<=len;i++)
    {
        curDigit = *num - 48; // "456" -> 4
        intNum += curDigit * pow(10, (double)(len - i));
        num++;
    }

    intNum *= minus;

    return intNum;
}

Friday 17 May 2013

Hi, Second week of oop344 has almost gone. I find the subject vary heavy. May be I am slow in following my professor..scared..but will do my best

Wednesday 8 May 2013

Welcome to Object Oriented Programming!!

My blogs are going to be about c++  which is an object oriented programming language.I wish to strengthen my programming skills through this blogs. Any suggestions and comments will be highly appreciated.

Thanks Everyone.