Learner010 99 Posting Whiz in Training

a lot thanks for your explanation . I really appreciate your answer.

earlier x was pointing to the address where v was stored but now i realize that this statement (x=new int;) will make x pointing to another location . therefore the statement(*x=12) will not write at the location where v is stored because x is now no longer pointing to v[because of this(x=new int)].

once again thanks.

Learner010 99 Posting Whiz in Training

consider the following code

afunction(int *x)
{
x=new int;
*x=12;
}
int main()
{
int v=10;
afunction(&v);
cout<<v;
}

i expected 12 as the output but its wrong and correct one is 10 . But i don't know how this is done internally ?
i was wondering if somebody could explain about it ?

thanks.

Learner010 99 Posting Whiz in Training

it seems the program I made, something out of scope with br[], Learner10, is it?

yes , it(ptrBr) points to memory location just below br[0].Thats why we need to increment it again and therefore use ++ with ptrBr.

Learner010 99 Posting Whiz in Training

this is because your last iteration make ptrBr point to some unknown location(i.e point to 1 location back).
let's see how your iteration works

iteration no      ptrAr         ptrBr
iteration 1       a[1]           a[3]
iteration 2       a[2]           a[2]
iteration 3       a[3]           a[1]
iteration 4       a[4]           a[0]
iteration 5       some unkown address becuase in this case index can't be exceed to 4 and can't be less than 0. therefore i think both point to +1(for ptrAr) and -1 (for ptrBr)

therefore after the loop , add the following statement for desierd output

ptrBr++;
ptrAr--;
Learner010 99 Posting Whiz in Training

i've declared pointer to char for getting input but i'm unable to get input using getline in this case :

char* str;
cout<<"enter string";
getline(cin,str);

its not working however i solved the issue using the following code(but i want that why the above code is not working)

string str;
cout<<"enter string";
getline(cin,str);

i want to know about this (char*) for getting input.

Learner010 99 Posting Whiz in Training

If it returns 0 then when it will return other than 0?

i'd be happy if you ask this question in connection with main function.

anyways , its nothing speical to return different values , you just need to use that value with return statement.See below :

int Factorial_Three()
{
return 6;
}
int main()
{
cout<<Factorial_Three();
return 0;
}

Here the function Factorial_Three returns the value 6(which is what you want(i.e. other than 0).And it return the value from where the function is called.Therefore it prints 6.

And whether function have any default return value?

for main function , its int. it means if your don't specify any return type then it will be considered as int by default. but it's not good practice , therefore always use int main() instead of main().

Learner010 99 Posting Whiz in Training

y would one need to swapp the numbers in real life? trickery? magic

do you mean applications of swapping ? if yes , agree with AD.
its used in sorting process.

lets suppose there are 3 values {3,2,1} at 3 location x,y,z respectively.And to sort these values in ascending order therefore we need to perform swapping as follow:

if 3 is bigger than 2 then swap the content of loc x and y
if 3 is bigger than 1 then swap the content of loc x and z and so on....

Learner010 99 Posting Whiz in Training

I don't know how or even if it is possible to retrieve customer details from my database using customer ID.

its possible if you have customer ID field in your database table.you have to use select command to retrieve data from the table.

press retrieve button, then it will go to my database in access, search for customer with given ID ,retrieve customer details and fill different text boxes on my form.

you have to write the code on the click event of the buttion.and there would be various ways for retrieving data from database. since i don't play with visual basic 4/5/6 therefore i can't tell the exact way to do this.

But i'm reading the book databases and i can provide the sql query for retrieving data from the table. this would be as follow :

"select * from table where id="+text1.text

and the result will be stored in the recordset further you can do the following to print the reuslt

text2.text=rs!field2
text3.text=rs!field3

and so on....

atlast , it's not possible to explain everything and if somebody write the exact code for you then it will go in vain becuase it seems you are also a beginner and you this will not provide the way to learn new things.

i'd highly recommend you to go through a good database tutorial so that you can understand what is connection string , what is connection , what is recordset etc.

Learner010 99 Posting Whiz in Training

i want to add a 2d array "M[row][col]" in my class but i don't know how to do it anyone help?

whats the problem with that?
i think it would be same with class concept(i've not started yet with class concept) .
just declare variable with 2 dimension will make it 2d array.

int ar[10][10];//this is 2d array

Learner010 99 Posting Whiz in Training

but i get the same memory address when i cout either fishp or &fishp.

Not possible.

if you use cout<<fishp then it print the address of the variable , it points to(therefore print the address of fish).

when you use cout<<&fishp then it print the address of the variable(fishp) itself.

therefore two differents addresses will be printed.

Learner010 99 Posting Whiz in Training

sorry for disturbing this thread. but i have confusions here:

if (!cin)

how does this statement is evaluated ?however i have played with cin and cout but never used them as such.

and one more thing :

!(cin >> value)

what does it mean ? you are placing this inside a loop(with or operator) , therefore i assume that it will return either true or false , don't know the exact value.

after seeing such statements , i think that either i learned in bad manner or books are bad(because they don't discuss more on this).

atlast , one more thing:

why are you using ios header file ? , i don't think that program really require this header file.

would you please explain these aspects(totally hidden for me upto now) ?
thanks.

Learner010 99 Posting Whiz in Training

return 1 if c=y and return 0 otherwise

for this , you need to declare a function of int return type.

function that compares values of 'c' and 'y'

just use == operator.

if(c==y)
return 1;
else
return 0;
Learner010 99 Posting Whiz in Training

what you have done so far , to solve this assignment.
nobody will provide assistance until they realize that you did a lot with it.

don't forget to post your code here.

rubberman commented: Well put! :-) +12
Learner010 99 Posting Whiz in Training

happy to see that somebody is really learning with my tutorials , its my great pleasure.

however , Now , i see that this tutorial is not complete . a few topics(like passing array , returning multiple values , call by reference etc). i'll add these here soon.

Learner010 99 Posting Whiz in Training

sorry , i thought that i was posting in C++ forum. thats why i used cout and cin.you can think of cin and cout as scanf and printf respectively.

anyways , i think that the pointer concept i explained , is also applicable to C as well as C++.

Learner010 99 Posting Whiz in Training

Having trouble understanding pointers

its not a good way for getting assistance and therefore never forget to specify the specific topic(like pointers with array , const pointer , pointer to pointer , pointer arithmetic etc.) ?

one more thing , in your case , you need a tutorial on it.What daniweb does is providing helps , it doesn't provide such a platform where one orders and another one serves , everyone here is independent to help . And they'll help where they think that the op did a lot to solve the issue but couldn't success.

what problem you are facing with pointers ?

pointer variable is such a variable that store the address of another variable.to make a variable a pointer ,you just need to add * before the name of variable thats about it.but pointers are very broad issues. however this is impossible to explain every aspect here, but i am trying to explain the basics of pointer here:

int x,y; //x and y are normal variable which'll hold integer value

int* ptr //ptr is a pointer variable which hold the address of another variable.

int *ptr_1 //ptr_1 is another pointer variable .Here the purpose is to the depict similarities between the syntaxes . i mean that int* ptr and int *ptr_1 . both are same

ptr=&x; //its initializtion of pointer. it hold the address of variable(variable x)

ptr_1=&y; //we could have done this when decalraing the variable *ptr_1. like int *ptr_1=&y;

Now , …

Learner010 99 Posting Whiz in Training

the problem is I dont know which one will be first to make a code.

i don't understand what you want to say

the output will be like this;
sample output
monthly sale=15250
commission=610

next output ;
monthly sale=-5
commission=invalid output

last output;
monthly sale=45280
commision=170

where is the code you've written to produce such output ?
But as a hint , i can recommend you to use of loop.

loop will help to produce the result more times(Looping allows to repeat statements).you need not write the code for 3 times , just put it inside loop body and put such condition which ensures that loop will run 3 times(i mean that condition must be true till 3 iteration).

for more information on loop , see my tutorial on loop , here

Learner010 99 Posting Whiz in Training

thanks
very nice explanation .
i got it even though i am not familiar with class concept .

i'll start learning on class concept next week.
once again thanks for your very nice explanation.

Learner010 99 Posting Whiz in Training

what does it mean by c++ executive ?

i haven't heard about this(may be because i am a beginner).

Learner010 99 Posting Whiz in Training

evenafter learning functions , i see a lot new things everyday in functions. its great because it gives the opportunity to learn new things.

today , i see a function which have const keyword with function , like this :

void fun_name() const{


}

i couldn't understand it . would you guys please explain it ?

Learner010 99 Posting Whiz in Training

some logical errors are there:

change line 45 with this(because there are 2 values then you have set 2 instead of 8)

 avgt += (low_temp[monthQuarters] + high_temp[monthQuarters]) / 2.0;

remove line 46 and place the following after the loop

 avgp  = totalp/4.0;
Learner010 99 Posting Whiz in Training

to get 36.00% , you need to change the code at line 13 with this:

decPercent = (decX / decCalories)*100

Learner010 99 Posting Whiz in Training

daniweb too slow , today.
what happened ?

Learner010 99 Posting Whiz in Training

problem display the unchange array

i don't see the code for displaying an array. you should use cout<< for displaying
i don't know what do you mean by the word unchange.

you should declare a pointer variable because i think you wanna play with dynamic array.so try this:

int* array;
cout<<"enter size";
cin>>size;
array=new int[size];

here is code for getting input:

for(i=0;i<size;i++)
{
    cin>>array[i];
}

and for displaying an array:

for(i=0;i<size;i++)
{
    cout<<array[i];
}

instead of code, you provide nothing.
please explain your question.

Ancient Dragon commented: right +14
Learner010 99 Posting Whiz in Training

agree with you. here , bin_number should be read as big_number.
and don't sweat the small stuff.

Learner010 99 Posting Whiz in Training

i was wondering if somebody could explain this concept with suitable example(i.e. code snippt).

Learner010 99 Posting Whiz in Training

what i learn about pointer to array is that

A pointer to array is a pointer pointing to an array

example:

int arr[10];
int* ptr;

ptr=arr; // pointer to array

and your statement is

int (*ptr)[10]; //pointer to array

would you please clear doubts about pointer to array(with little easy code) ?

Learner010 99 Posting Whiz in Training

int (*pa)[10]; // A pointer to an array that can store 10 integers

does that equivalent to int *pa=new int[10]; ?

Learner010 99 Posting Whiz in Training

it should be

#include<iostream>
using namespeace std;
int main()
{
int num,x=1;
cout<<"enter number";
cin>>num;
if(num%2==0)
{
    cout<<"Even";
    for(;x<=10;x++)
    {
    cout<<(2*x)<<endl;
    }
}
else
{
    cout<<"Odd";
    for(;x<=10;x++)
    {
    cout<<(3*x)<<endl;
    }
}
return 0;
}

and don't forget to use code button when you are posting code.

Learner010 99 Posting Whiz in Training

we don't do your homeworks , its your duty to complete it.
but as a help i can suggest the following structure , you can use to solve your assignments.

if(n is even)
{
//write code to print the table for 2
}
else
{
//write code to print the table for 3
}

to check if n is even or odd , you can use % with 2(n%2) and check if the result of the expression is equal to 0 then its even otherwise odd.
And nothing extra i can do for you , if you fail to prove what you done so far to solve your assignment.

Learner010 99 Posting Whiz in Training

why is this not possible to create an integer array using pointer (same as what we do with characters . example char* str="hello world" )

why the statement below is illegal :

int* pointers=10,20,30;
cout<<pointers[1];

but this is legal

char* str="hello world"
cout<<str[1];

please explain about these aspects.
i'm highly consfused with it.

Learner010 99 Posting Whiz in Training

is it possible to declare integer pointer contain 3 values ?

if yes , then how can i declare such pointers ?

Learner010 99 Posting Whiz in Training

I read about pointers and it says that
array names can be used as pointer constants and pointers can be used as array names

and here is an example that prove the first statement (array names can be used as pointer constants)

#include<iostream>
using namespace std;
int main()
{
    int arr[3]={10,20,30};
    for(int i=0;i<3;i++)
    cout<<*(arr+i);
    return 0;
}

Do you have any example that prove the second statement(pointers can be used as array names)?

Learner010 99 Posting Whiz in Training

ok ,
i got it.

thanks everyone for passing your suggestions over this thread.

Learner010 99 Posting Whiz in Training

thanks AD for good explanation
i got the concept what you want to say but i was wondering if you could give sample code here which uses two files(both a.cpp and b.cpp) in a progarm.

i don't know how a program can use two files(up to now ,i haven't seen such a topic in the book).

Learner010 99 Posting Whiz in Training

thanks mike for very good explanation .
but before watching your reply here i done it , here is what i did:

i created functions.h and define functions there and compile the code. now create another file uses.cpp and add header file there as #include "functions.h" and code run without any error.

actually i don't see any reason in support with why to declare function prototypes in functions.h and define them in functions.cpp ?

what if i directly define the functions in functions.h .
it worked for me.

Learner010 99 Posting Whiz in Training

ok
i done what i wanted
i created a file functions.h and write all the code there and compile this file and here is what i used to include this file

#include "functions.h"

But , i want to learn the way you suggest(adding libraries to cpp files), but i am unable to generate .obj files. here is what i've done :
i create functions.cpp and when i compile this file , compiler generate functions.o . so how to generate functions.obj.

Learner010 99 Posting Whiz in Training

okay ,
now i decide to create a library , for this i have move the code to functions.lib file and compile it.

now how can i add this library to my program ?

i use code::block compiler

Learner010 99 Posting Whiz in Training

I am new with the c++ code,

I'm also new , and new user can learn and finally becomes expert.And c++ is very easy to learn.

Write a c++ program that may be use to compute the area of square (area=sideside) or a triangle (area=1/2base*height).

i think nobody will write for you.you should do your homework with your own efforts.we will try to solve it ,if prove that you played much with the code but unable to find the solution.

After prompting the user to type the first character of the figure name (S or T) if S you will compute the area of square, if T you will compute the area of trianglE.

try this:

char ch;
cin>>ch;
if(ch=='s')
//call related function 
else if(ch=='t')
//call related function

subprogram is another term for function/subroutine. It is very easy to learn and Here is my tutorial on functions in c++.

Learner010 99 Posting Whiz in Training

hello ,

after learning on functions in c++ , i created several functions and now i wanna create a gourp which will have these several functions at a place(i think its done with header file).

so, i think if i create a header file and include these all these functions there then it will be easier.But i don't know how to create a header file which includes several functions.

the only thing i know about header files is that "they have .h file extention and they include various constants and functions".

here is for what i wanna create header file :

    int factorial(int n)
    {
        if(n==0)
            return 1;
        else
            return n*factorial(n-1);
    }

    Bool IsEven(int n)
    {
    if (n%2==0)
    return true;
    else
    return false;
    }

    double sqr(int n)
    {
    return n*n;
    }

and now how can i create the file and how can i add this file to my programe.
please guide me.

thanks in advance :)

Learner010 99 Posting Whiz in Training

your current form refers to as Me.
so , if you coding behind Form2 then you have to useMe.Textbox1.Text instead of Form2.Textbox1.Text.

but if you are working on Form1 and you wanna access textbox exist on Form2 then you have to use

Form2.Textbox1.Text

Learner010 99 Posting Whiz in Training

i use getline(cin,name);
but problem will still exist until you clear the buffer .

write this to clear the buffer :

cin.ignore(numeric_limits<streamsize>::max(), '\n');

don't forget to include <limits>.

please correct me if i'm wrong.

Learner010 99 Posting Whiz in Training

Because it cannot refer to itself through its default instance name , for this you have to use Me

try this:

Me.Textbox1.Text="Hello"

Learner010 99 Posting Whiz in Training

please check your update statement(i will start programming with database very soon but before right now , i am reading Book on SQL).
i saw there the correct syntax for update statement is:

UPDATE enroll SET username='" & textbox1.Text & "' where ID=" & _UserId

, is used when you are gonna update multiple fields.

Learner010 99 Posting Whiz in Training

functions are very easy to learn (i recently learned it , except recursion, which today i'll finish).just read My Tutorial and read the section titled "Argument and return". if you read this tutorial carefully , you'll easily solve it.

try to do that with your own efforts , we'll provide assistance only and only if you face any problem(but this happens when you initiate to create it).

and don't forget to post your code in which you got error.

ddanbe commented: Good advise. +15
Learner010 99 Posting Whiz in Training

As usual, after learning new stuff, I write on it. Yesterday I finished learning on "Functions in C++" and found that functions are very easy to learn and useful. Hope this tutorial helps beginners.

What is function?

Sometimes when we want to execute a specific task wherever it's needed, instead of writing the entire code again, we should create a block of code that is called a function. Once you define the functionality inside the function body, you can call it whenever and wherever it's needed.
Functions prevent code repetition.

There are 2 terminologies:

  1. Defining a function: process of creating functionality
  2. Calling a function: process of executing functionality

Function is a subprogram / block of code which is responsible for a specific task.
We can divide functions in 2 major part:

  1. Library function
  2. User defined function (UDF, further in this tutorial, I’ll use this term instead of "user defined function")

In this tutorial, I'm not covering library functions. I don’t think that library functions require a tutorial, because library functions are readymade code, you need to add header files where these functions are defined and just call them. It's very easy.

Example: to calculate the length of a string, you need std::strlen() function and this is defined in cstring header file.

User defined functions are those function that user creates for a specific purpose.
For example, if you are creating an application which allows a user to issue maximum of 6 books, with 6 …

Learner010 99 Posting Whiz in Training

i want to add child forms in mdi parent form and i done this but the problem is :

i have an picture box in the top of MDI form and now here i want is that the child form should load after that picture box and this does not .
So , How can i do this ?

Learner010 99 Posting Whiz in Training

once you update the regedit information you have to restart your computer and then try to format the disk with the as usual method(i mean right click and select format , quick format)

Learner010 99 Posting Whiz in Training

sorry
i didn't see that .

but you can with regedit
this is HKEY_LOCAL_MACHINE ----> SYSTEM ----> control ---->StorageDevicePolicies

now set write access by setting there 0.

if you don't find StorageDevicePoloices and then you can manually create it.

Learner010 99 Posting Whiz in Training

using DISKPART

select the disk and then type the command

attributes disk clear readonly