67 Posted Topics
Re: I preffer the following alternative that print an inverted trinagle with any specified number of lines: #include <iostream> void makeInvTri(int rows, int spaces = 0) { if (rows < 0) return; int r = rows; int s = spaces; while(s--) std::cout << " "; while(r--) std::cout << "*"; std::cout << … | |
Re: You can try something like this: class myIntArray { int* data; public: myIntArray(int size) : data(new int[size]) {} ~myIntArray() {delete[] data;} int& operator[] (int pos) {return data[pos];} //... }; | |
Re: The analitical answer is 0.440244, so this is the limit that you must arrive with a lot of intervals. Here you have your code modified to the right answer: #include <iostream> #include <cmath> using namespace std; double f(double x) { return ((0.6369)*sin(sin(x))*sin(x)); } int main() { double a = 0.0; … | |
Re: A function can return a value, for example: `int addOne(int a) {return a+1;}` and be used like: `b = addOne(b);` Also it can not return a value, for example: `void addOne(int& a) {a = a+1;}` and be used like: `addOne(b);` In this case, you have both alternatives and you can … | |
Re: `void* memset( void* dest, int ch, std::size_t count );` Converts the value ch to unsigned char and copies it into each of the first count characters of the object pointed to by dest. This means that if your destination can´t be looked as unsigned chars, memset will not work. For … | |
Re: In C/C++ you must define everything befor use it. For example, if you need a variable to store an integer --say a--, first you must define it like: `int a;` and later you can use it like `a=3;`. The same happens, for example, with functions. Suppose that you have declared … | |
Re: You could use something like: string s; cin >> s; for(char c : s) cout << c << ", "; but you need to solve how to not write the last ',' yet. Also this has the problem to work with letters and numbers. Anyway, this is a start point … | |
Re: I don´t think that a^n = O(n!). Supposing that O(x) means the order of magnitude of the number of computer operations you need to compute something, this means that O(2) need 2 computer operations to compute something and O(4) needs 4. Now suppose that a^n = O(n!) is true, then … | |
Re: I don´t think thos is a C++ problem. It seems an operating system problem. Which is your operating system? | |
Re: What is the proble you have with this code? 1 Do not compile? 2 Do not give the expected results? 3 You do not undertand what is does? 4.... | |
Re: You could user something like: struct Number { union Value {int i; double d;} value; enum Type {integer, real, none} type; Number(): type{Type::none} {} void setvalue(int i) {value.i = i; type=Type::integer;} void setvalue(double d) {value.d = d; type=Type::real;} }; and later use it like: Number n; n.setvalue(3); if(n.type == Number::Type::integer) … | |
Re: You could define the following function: char invert(char c) { return isupper(c)? tolower(c) : toupper(c); } and then use like this: for(int i=0; input[i] != '\0'; i++) input[i]=invert(input[i]); | |
Re: You could use something like this: std::map<char,int> dict; int c; while((c = getchar())!=EOF) dict[c]++; for(char& p : dict) std::cout << p.first << ": " << p.second << std::endl; | |
Re: I would want to add the following: C: C compiler is written in C. C++: C++ compiler is written in C++. Java: Sun actually has multiple JVMs. The HotSpot JVM is written largely in C++, because HotSpot is heavily based on the Animorphic Smalltalk VM which is written in C++. … | |
Re: This should work: #include <iostream> using namespace std; int main() { int var; cout << "please enter any integer" << endl; while(!(cin>>var)) { cin.clear(); cin.ignore(1000,'\n'); cout << "Error, enter the right thing" << endl; } cout << "You entered: " << var << endl; return 0; } Enjoy :) | |
![]() | Re: Your problem is that char grades[] don´t have the required space of memory. Try something like: char grades[100]; and be sure that counter is alway below 99. |
Re: This easy code delete multiple occurences of ItemType x from a and works even for an array plenty of only x: void SortedList::DeleteItem(ItemType x) { int i=-1, j=0; while(j<MAX_ITEMS) { while(j<MAX_ITEMS && a[j]==x) ++j; if(j<MAX_ITEMS) a[++i]=a[j++]; } MAX_ITEMS=i+1; } Enjoy :) |
The End.