There is no guarentee that one byte = 8 bits.
Though there's a guarantee that char
(synonymous with a byte in C) is at least 8 bits. CHAR_BIT
may be more than 8, but never less.
There is no guarentee that one byte = 8 bits.
Though there's a guarantee that char
(synonymous with a byte in C) is at least 8 bits. CHAR_BIT
may be more than 8, but never less.
I think WYSIWYG is ideal for the display aspects of web development (HTML and CSS, specifically), and in the next 10 years the tools will hopefully be good enough that we don't need to drop down to the code to do what we want. As it is, drag-drop-configure gets you close, but not quite all the way, and I find myself dropping down to code views to tweak things.
All of the back-end and custom scripting probably won't be replaced with visual designers any time soon.
1 - why some C++ PRO don't advice me use these code?(making properties)
Because it's awkward (as you've discovered), unnecessary, and a complete solution isn't as good as what you'd get with another language like C#. C++ "pros" do without excessively awkward fluff.
when somebody make a forum it means he wanna make a situation to solve other pepole problems.
Though not to the exclusion of effort on the part of the person with the problem. We'll help you solve your problem, not solve it for you so that you can sit back and enjoy the results without doing anything on your own. This is stated clearly in Daniweb's rules.
My question is how does the first example work since i haven't used the .Dispose() method
How would that stop the code from working? You've merely failed to release resources, which depending on the resource involved may or may not cause issues down the line.
I m just unsure sometimes when to use using when not.
If a class implements IDisposable
, you should either use a using
statement, or call the Dispose
method when you're done with the object. I include both options even though using
should be preferred because there are situations where a using
is awkward, and rolling everything up into a try..finally
is cleaner.
One more question can you elaborate on the need for returning a const reference?
A const reference would be returned when you want a read-only element, but don't know if the type represented by V
is cheap to copy or not. Returning a non-const reference is nonsensical if the matrix itself is const (ie. const Matrix<int, 10> cmat;
), so when you write a const operator, it should return a const reference as well. You'd have two versions, one const and one non-const to account for these cases:
// For non-const objects, allows modification of the reference
V& operator()(int row, int column);
// For const objects, disallows modification of the reference
const V& operator()(int row, int column) const;
Compare and contrast:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* toBin(int);
int main(void)
{
int n;
char *out;
printf("\n Enter no : ");
scanf("%d", &n);
out = toBin(n);
printf("\n OUT %s\n", out);
free(out);
return 0;
}
char* toBin(int d)
{
int d1 = d, r = 0, i = 0;
char *s;
s = (char*)malloc(200 * sizeof(char));
while (d1 > 0) {
r = d1 % 2;
d1 = d1 / 2;
s[i] = r + 48;
i++;
}
s[i] = '\0'; /* Always close the string! */
_strrev(s);
printf("\n rev ptr %s", s);
return s;
}
Please read our rules concerning homework. We don't just give away code for homework problems without proof of effort, and even then most of us won't write the whole thing for you, we'll just push you in the right direction.
Im trying to accomplish to save both aco####s and settings into the same xml like so
Then if you want to continue using XmlSerializer
, you should wrap those two classes in a another class, then serialize that one:
class AppSettings
{
public General GeneralSettings { get; set; }
public List<Account> Accounts { get; set; }
}
XmlSerializer
treats the entire class hierarchy as a single self-contained XML entity, which means the highest level class is your XML root.
Post your current code.
i have 1 question: for use dynamic arrays, can i use normal variables instead pointers?
Pointers are normal variables. But when it comes to "dynamic" arrays, it's a bit of a misnomer because you're not creating an array, you're simulating one with dynamic memory allocation.
Really the best you can get is to hide the pointers in a class implementation. Both std::string
or std::vector
are "dynamic" arrays under the hood, but it's hidden by the class interface.
using this code its only print success..
That's the point of the program, to tell you whether the file was opened successfully.
i want to display file in notepad..
Please note that we're not going to write your program for you. You asked a specific question and got a specific answer. Now it's up to you to ask more specific questions or apply what you've learned in this thread to your actual program.
heres a nice way for build 1 class 100% 'static'
The "static" object must be in scope wherever you use it, which essentially means it must be global (usually not a good idea). Further, you cannot access "static" members through anything except the "static" object. Other objects will have their own copies of the "static" members, which completely defeats the purpose.
I wouldn't recommend that solution in general, and I certainly wouldn't describe it as a static class.
then what should i do....?
Call malloc
in toBin
and free the returned pointer in main
.
The headers themselves don't do anything, they just provide declarations so that code will compile. You also need the underlying libraries, which if they aren't already provided by the implementation, most likely won't transfer easily.
Your best approach would be to determine which functions you're using and then look for alternatives on the new implementation.
You're returning a reference to a local variable. The local variable gets destroyed, so the reference is dangling. Just return a reference to myStore[row]
directly:
template<class V, class I>
V& Matrix<V,I>::operator()(int row, int column)
{
return myStore[row][column];
}
Alternatively you can make a local reference to the row, then return a reference to the column:
template<class V, class I>
V& Matrix<V,I>::operator()(int row, int column)
{
Array<V,I>& myArray = myStore[row];
return myArray[column];
}
On a side note, you should consider overloading the operator for const objects as well, and return a const reference:
template<class V, class I>
const V& Matrix<V,I>::operator()(int row, int column) const;
But as i am returning a pointer s I can't free it before returning it.
The caller has to free it. While the ideal for robustness is to have memory allocated and freed at the same execution level, that's not always practical.
I take a char array[100],Perform operation on it,and then point my pointer to it at the end.
In this case you're returning a pointer to a local object. The local object gets destroyed when the function returns, so the caller gets what's called a dangling pointer--it points to garbage by definition.
Itworks fine for unsigned variables but the signed output is not correct for int or long.
You seem to have missed the part where I stated that overflowing a signed type is undefined behavior. The same method that works for unsigned types is broken on signed types. There's no safe way to do what you want with signed types, which is one reason why the standard library provides macros that tell you the range limits for the implementation.
Step back a moment and consider why you need clrscr
or any variations. It's my fairly strong belief that when you start needing to do any non-linear manipulation of the console, you should probably bite the bullet and move to a GUI.
That said, if you're on a Windows system you can write a clrscr
(all of the conio library, in fact) that's portable to any Win32 compiler: https://code.google.com/p/c-standard-library/source/browse/src/internal/_sysconio.c. The relevant parts are:
#include <Windows.h>
void clrscr(void)
{
HANDLE sys_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO info;
COORD topleft = { 0 };
DWORD size, written;
if (!GetConsoleScreenBufferInfo(sys_stdout, &info))
return;
size = info.dwSize.X * info.dwSize.Y;
/* Overwrite the visible buffer with blank spaces */
FillConsoleOutputCharacter(sys_stdout, ' ', size, topleft, &written);
/* If the first call succeeded, this one should too */
GetConsoleScreenBufferInfo(sys_stdout, &info);
/*
Fix the character attributes (color, etc...) for the "whitespace"
if they weren't set to defaults. Otherwise they would be lost.
Finally, reset the cursor position.
*/
FillConsoleOutputAttribute(sys_stdout, info.wAttributes, size, topleft, &written);
SetConsoleCursorPosition(sys_stdout, topleft);
}
However, the values for INT_MIN and INT_MAX are shown in the appendices as being the same as SHRT_MIN and SHRT_MAX repsectively.
The minimum range of int is indeed 16 bits, even though you're unlikely to see less than 32 bits on a modern implementation.
I was hoping that by increasing a "short" variable, for example, to EOF, it would stop within its range. Why is this not occuring?
EOF is a negative quantity that may or may not be -1. What you're actually doing with that code is invoking undefined behavior by overflowing a signed integral type. A safer approach is to use unsigned types instead (since they have defined wraparound behavior), then stop when the value wraps to 0:
unsigned char x = 0;
unsigned short y = 0;
unsigned int z = 0;
while (++x != 0);
while (++y != 0);
while (++z != 0);
printf("Range of unsigned char [0,%u]\n", --x);
printf("Range of unsigned short [0,%u]\n", --y);
printf("Range of unsigned int [0,%u]\n", --z);
I personally from my experience feel that masters degree is not required to become a good computer programmer.
You don't need any degree to become a good programmer. You may need a degree to get a job as a programmer, but typically that's for your first job and subsequent employers only care about experience.
Judging from your desired path, I'd go for the IS course since it's more in line with where you eventually want to be. Not to mention that general IS knowledge is beneficial as a developer too.
For what purpose? This seems pretty sketchy.
hehehe ^^ :P sory if mah englizh iz not gud, datz kitteh language....
Please write in full sentence English without excessive "txt", "leet", or "chatroom" speak (which includes "kitteh" language) as per Daniweb's rules. Thank you. A "kitteh" word here and there is fine, but even I'm finding your posts difficult to read, and that's saying something.
If I understand you correctly, you want to display contents of the Access table within your form, but records should be unique and not duplicated in the form if a record is searched for multiple times?
While your childish little writing dialect is cute, it's very rude to the non-native English speakers on Daniweb because they may have a very hard time deciphering it.
As for the problem itself. What is the purpose of this logic? What goal are you trying to accomplish?
Let's use a simple example of a tree with only one node. If the new node you're adding is to be added to the right subtree, the first if
will set ptr
to NULL
. Then the second if
will test ptr->info
, which is dereferencing a null pointer:
The reason you need an else if
is because you're moving either left or right, not potentially both. You could check ptr to see if it's NULL
in the second if
, but that's unnecessary extra work.
Line 54 should be an else if
.
Please note that I'm using the word "ignorant" with its dictionary definition (ie. lacking knowledge or education), and it's focused strictly on this single topic, not general ignorance. It's not intended to be judgmental or a negative slur in any way, just an observation that what we're dealing with here is an uninformed opinion.
Please post actual C code that you want to add this feature to. If you're working with a pointer to a string literal then you can't modify it.
In my experience, deductions from ignorance don't produce accurate results. No offense to your dad, but my usual response to folks who confidently make shit up is to nod and promptly change the subject.
So, have you learned C++ at all, or are you just guessing as to what the syntax is? Because your code is very clearly nonsensical. At this point I'd recommend re-reading the chapter on functions and classes in your book until you understand what you're doing wrong.
I'd also strongly recommend using unique names for each unique variable, because your re-use of set
is sure to cause heartache.
Is the array holding the string large enough for another character? Because if so it's a simple matter of:
s[size] = c; // Overwite the nul with a new character
s[++size] = '\0'; // Terminate the string after the new character
is the data likely to get damaged in a short period of time(3-4 months since writing let's say) on a flash drive?
Not unless you have low quality hardware. I'd ask your dad to cite his references, because unless there have been multiple peer reviewed studies from reputable sources that conclude "likely" damage in flash drives, I'll simply call bullshit and leave it at that.
the data on CDs is much more less likely to get distorted/destroyed
That's easy to refute. Grab a CD and scratch it up on either side. You've distorted/destroyed the data with ease. Now do the same thing with a flash drive and see how much harder it is to physically damage.
However, with proper storage, optical media has a much longer shelf life than solid state. This is a direct result of intended usage though. A CD or DVD isn't designed as a pluggable hard drive that should be read from and written to on a regular basis.
I think you're both missing the target a bit, since CD/DVD and memory sticks solve a different problem. They co-exist quite nicely. ;)
flash drives are (very)prone to have information errors because of physical processes?
Not if it's quality hardware. Has your dad been buying the cheapos at the cash register? Those are shit.
Let's start with this: what is set
? Make up your mind, is it a function, a data member, or a local variable? What do you want to do with it? Right now your code pretty much depends on the compiler being psychic every other line.
#include <iostream>
#include <string>
#include <fstream>
int main()
{
using namespace std;
const int rows = 4;
const int cols = 3;
ifstream file("test.txt");
if (file.is_open()) {
float r[rows][cols];
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
file >> r[i][j];
file.get(); // Throw away the comma
}
}
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
cout << r[i][j] << ' ';
}
cout << '\n';
}
}
}
Here's a pro tip for when you're first starting out. If you need to modularize files, start by putting it all in a single file, like main.cpp, and get the program working. Then you can modularize it by moving functions to other files and creating headers to declare those functions.
This way you can avoid the nuances of structure (ie. gluing multiple files together) when you're still struggling with the basic functionality.
Make necessary assumptions wherever required.
I assume you're a lazy student who wants someone else to spoonfeed you answers. I assume any attempts to help will be sucked up like a leech and followed by more begging. Finally, I assume that this is also a drive-by, and closing this thread won't cause you any heartache.
So...I'm closing the thread as a homework rule violation.
Define "help", because it sounds a lot like you want us to do your homework for you.
Thanks deceptikon for ur code and Checked it today and it's giving me some error, Can u tell me where I am going wrong
You're probably not using a compiler that supports C++11, or compiling with that switch disabled. However, I can't tell you what's wrong when you don't tell me what the errors are. :rolleyes:
is this possible to perform overloading on the basis of their return type ?
i think NOT POSSIBLE.
Correct, the return type doesn't contribute to the function's signature, and therefore you can't overload just on return type. Parameters and constness are the two biggies in terms of how a function signature is generated.
Two different concepts that unforunately seem similar due to the "over" part.
Overloading is when you have multiple functions that use the same name, but have different parameter lists. The function is said to be overloaded since calls that provide different arguments will call the correct function:
void foo() { cout << "No parameters\n"; }
void foo(int) { cout << "One parameter\n"; }
int main()
{
foo(); // Prints "No parameters"
foo(123); // Prints "One parameter"
}
Overriding is a concept related to polymorphism where a derived class' version of a member function is used instead of the base class' version. The derived class' function is said to override the base class' function:
class base {
public:
virtual void foo() const { cout << "Base\n"; }
};
class derived: public base {
public:
void foo() const override { cout << "Derived\n"; }
};
int main()
{
const base& obj = derived();
obj.foo(); // Prints "Derived"
}
I would like to ask if its possible to change the size of the array
No, arrays are given a size at compile time and that cannot be changed at runtime. There are ways of simulating an array that can be resized, but those methods are already incorporated into standard classes such as vector
or string
. You should prefer those libraries to rolling your own ad hoc code.
Does your teacher want you to take the value as-is or round it? Regardless, you need to keep only the first two digits after the radix for the purposes of this program, but whether you round (and how you round) can affect the result.
A naive approach (which should be sufficient for this exercise) is to extract the two digits after the radix and convert it to int
. Then look for the third digit after the radix and if it's greater than 5, round up. This should give you a decent facsimile of the rounding that cout
performs:
#include <iostream>
using namespace std;
int main()
{
double value = 14.49999;
int ivalue = (int)((value - (int)value) * 1000);
// Remove the dollar amount and convert cents to int
int cents = ivalue / 10;
// Find the rounding delta
int delta = ivalue % 10;
cout << "Cents: " << cents << '\n';
cout << "Delta: " << delta << '\n';
if (delta >= 5) {
++cents;
}
cout << "Cents rounded up: " << cents << '\n';
}
If you don't need to round, then you can take the cents as-is and call it good. But financial applications typically round up. ;)
Your code is horribly broken. I'm guessing you meant to post the errors you're getting and ask what's causing them, as per this helpful guide.
Let's step back a moment. How well do you know C? Granted I didn't provide details, but what I said should be enough to get you started unless you're a total beginner with no clue how to read and write files or about basic string manipulation.
Should I go for a degree in Computer Science, or are there other educational paths I should take?
Since you're already in the field and have experience, I wouldn't waste my money on a degree. You could buy a CS textbook or two and be just as well off, with the only difference being no $xxx,000 piece of paper when you're done.
Focused classes would be much more effective and also cheaper than a full undergrad degree course. You might look into certification courses as well, which often offer a discount on the exam as a bonus.
Any flat file format will work then. CSV is a common one, and if you're not going to have embedded commans in your values, the format is both simple and easy to parse.
What kind of variables? Are we talking just scalar values or data structures? The former are easy to export, but the latter could take a little thinking to get a format that's easy to both export and subsequently import.
And in all reality I will be working with more than two files because I am working on an external polyphase sort
Okay, you're making it too complicated. You'll already have a collection of stream objects for a polyphase sort, so just mark the index of (or have a reference to) the current output stream and update it as necessary. That's so much more intuitive than swapping streams left and right, even if you were using C++11.
Thanks and How to write the file path in program?
...um, you may want to drop back a bit and study file I/O in C++. I had been operating under the assumption that your problem was parsing the format, not the basics of how to read a file.