Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,217 members, 7,818,751 topics. Date: Monday, 06 May 2024 at 12:15 AM

. - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / . (1748 Views)

We are all Geeks, Discuss your ideas / Jokes For Geeks / --theory: Geeks, Computer Hobbyists And Programmers Hardly Gets The Girl Quick? (2) (3) (4)

(1) (Reply) (Go Down)

. by holyboss: 1:20pm On Nov 20, 2015
.
Re: . by codemarshal08(m): 7:36pm On Nov 20, 2015
Hmm bro. what do you not understand in those codes ?
Re: . by Nobody: 10:54pm On Nov 20, 2015
Lazy man!
Make we do your home work for you?
Re: . by Intellab(m): 11:39pm On Nov 22, 2015
I think in 2, result will be displayed as 30.0. You declared num1 as integer. For num2, you should use double instead. //I'm not a c++ pro.
Re: . by Nobody: 2:05am On Nov 23, 2015
holyboss:
Please kindly help on the following question:

1. Explain the following code snippet

Fstream file
file.open(“/mydir/data.bin”, ios::in)
while(file)


2. Explain what the following code is doing?

#include <iostream>
using namespace std;
int main()
{
int num1 = 10;
float num2 = 20;
cout << sizeof(num1 + num2);
return 0;
}



The first one is like a flat-file database. Simply put Notepad.. It uses a notepad or text editor to store data even after the program stops running!! Enough of the explanation, the above program in number 1(one) is only trying to access a text document from the stipulated path name, the "while" statement checks if it really does exist.

2. Although I haven't debugged your codes but I think I have an idea of what that does, you see my friend when you actually want to determine the size of let's say a variable in the memory, such function could be used. In context to this program, it actually determines the memory size or actual size of each variables then proceeds by determining its arithmetic sum, of cause you know it provides the output!!!!


I hope this was of help to you!!! Have a nice day!!!

3 Likes 2 Shares

Re: . by Nobody: 8:53am On Nov 23, 2015
Your second code is wrong.

Why use int and float at the same time?

Code should have looked like this


#include <stdio.h>
int main()
{
Int num1;
Int num2;
Int answer = num1 + num2;
Cout << "Answer "<<answer endl;
return 0;
}


Now the first one apparently u using ofstream(file stream) which you must include the header file

#include <fstream>
Re: . by Nobody: 8:55am On Nov 23, 2015
Ezechinwa:


The first one is like a flat-file database. Simply put Notepad.. It uses a notepad or text editor to store data even after the program stops running!! Enough of the explanation, the above program in number 1(one) is only trying to access a text document from the stipulated path name, the "while" statement checks if it really does exist.

2. Although I haven't debugged your codes but I think I have an idea of what that does, you see my friend when you actually want to determine the size of let's say a variable in the memory, such function could be used. In context to this program, it actually determines the memory size or actual size of each variables then proceeds by determining its arithmetic sum, of cause you know it provides the output!!!!


I hope this was of help to you!!! Have a nice day!!!

Using sizeof to add and using float? This code will produce powerful errors.
Re: . by Diakon(m): 11:15am On Nov 23, 2015
holyboss:
Please kindly help on the following question:

1. Explain the following code snippet

Fstream file
file.open(“/mydir/data.bin”, ios::in)
while(file)


2. Explain what the following code is doing?

#include <iostream>
using namespace std;
int main()
{
int num1 = 10;
float num2 = 20;
cout << sizeof(num1 + num2);
return 0;
}



How come no one has given a sensible answer to number 2?
Your code in number two adds your two variables. It promotes the int to a float (in order to enable the addition) and this results in an answer of type float. Thus, the sizeof operator gives you the size of a float, which on most architectures, is 4.
Re: . by mexzony: 3:40pm On Nov 23, 2015
gimakon:
Your second code is wrong.

Why use int and float at the same time?

Code should have looked like this


#include <stdio.h>
int main()
{
Int num1;
Int num2;
Int answer = num1 + num2;
Cout << "Answer "<<answer endl;
return 0;
}


Now the first one apparently u using ofstream(file stream) which you must include the header file

#include <fstream>
I am not a c++ geek but the system should be able to implicitly convert an int to a float or vice versa.
I think it returns the size of the number the answer in bits or something.my own guess
Re: . by holyboss: 4:01pm On Nov 23, 2015
gimakon:


Using sizeof to add and using float? This code will produce powerful errors.
The code is correct, run it with DEV or CodeblocK, It will display 4
Re: . by holyboss: 4:02pm On Nov 23, 2015
TOmmyJidex:
Lazy man!

Make we do your home work for you?


Bros wetin na!
Re: . by holyboss: 4:04pm On Nov 23, 2015
mexzony:

I am not a c++ geek but the system should be able to implicitly convert an int to a float or vice versa.
I think it returns the size of the number the answer in bits or something.my own guess
Your contribution is appreciated, bro..
Re: . by holyboss: 4:04pm On Nov 23, 2015
Diakon:



How come no one has given a sensible answer to number 2?
Your code in number two adds your two variables. It promotes the int to a float (in order to enable the addition) and this results in an answer of type float. Thus, the sizeof operator gives you the size of a float, which on most architectures, is 4.
Thanks man. Yal dah bomb!
Re: . by holyboss: 4:05pm On Nov 23, 2015
gimakon:
Your second code is wrong.

Why use int and float at the same time?

Code should have looked like this


#include <stdio.h>
int main()
{
Int num1;
Int num2;
Int answer = num1 + num2;
Cout << "Answer "<<answer endl;
return 0;
}


Now the first one apparently u using ofstream(file stream) which you must include the header file

#include <fstream>
Thanks man
Re: . by holyboss: 4:07pm On Nov 23, 2015
codemarshal08:
Hmm bro. what do you not understand in those codes ?
It has been answered, thanks
Re: . by holyboss: 4:23pm On Nov 23, 2015
Ezechinwa:


The first one is like a flat-file database. Simply put Notepad.. It uses a notepad or text editor to store data even after the program stops running!! Enough of the explanation, the above program in number 1(one) is only trying to access a text document from the stipulated path name, the "while" statement checks if it really does exist.

2. Although I haven't debugged your codes but I think I have an idea of what that does, you see my friend when you actually want to determine the size of let's say a variable in the memory, such function could be used. In context to this program, it actually determines the memory size or actual size of each variables then proceeds by determining its arithmetic sum, of cause you know it provides the output!!!!


I hope this was of help to you!!! Have a nice day!!!

Thanks Man
Re: . by tdayof(m): 8:23pm On Nov 23, 2015
holyboss:
The code is correct, run it with DEV or CodeblocK, It will display 4
hmm
Re: . by holyboss: 3:38pm On Nov 24, 2015
tdayof:
hmm
*coverFace*

longest time, what's upping??

(1) (Reply)

Your Guide To Android Developer Options / Cost Of An App Like Instagram / How To Convert EML File Into PST

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.