Can anybody explain--please..
Usually overloading operators << and >> should return ostream by reference. But in our project why does it return console by reference??
Dimple's blogs on OOP344
Wednesday, 2 October 2013
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
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, 29 July 2013
This is how we can get rid of white space from our code and auto format it on visual studio
Select entire code
CTRL+K and then CTRL+D
It format the code and increase readability.
CTRL+K and then CTRL+D
It format the code and increase readability.
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?????
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
Subscribe to:
Posts (Atom)