67 Posted Topics

Member Avatar for omar.elbakly.95

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 << …

Member Avatar for Maritimo
0
1K
Member Avatar for bilal qadri

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];} //... };

Member Avatar for Maritimo
0
95
Member Avatar for Auroch

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; …

Member Avatar for Auroch
0
2K
Member Avatar for redtribal23

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 …

Member Avatar for redtribal23
0
149
Member Avatar for COKEDUDE

`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 …

Member Avatar for Maritimo
0
189
Member Avatar for coding101

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 …

Member Avatar for Maritimo
0
109
Member Avatar for magdaekeya

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 …

Member Avatar for Maritimo
-2
78
Member Avatar for zeedote

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 …

Member Avatar for sepp2k
0
200
Member Avatar for cambalinho

I don´t think thos is a C++ problem. It seems an operating system problem. Which is your operating system?

Member Avatar for cambalinho
1
216
Member Avatar for melisasimjiaqi

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....

Member Avatar for Maritimo
0
205
Member Avatar for csnerd2020

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) …

Member Avatar for Maritimo
0
191
Member Avatar for exoruel

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]);

Member Avatar for Maritimo
0
174
Member Avatar for dori24

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;

Member Avatar for Maritimo
0
74
Member Avatar for ckide

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++. …

Member Avatar for Maritimo
0
470
Member Avatar for samson.dadson.3_1

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 :)

Member Avatar for samson.dadson.3_1
0
2K
Member Avatar for jsussarredondo

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.

Member Avatar for Maritimo
0
145
Member Avatar for saeed.albahri1

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 :)

Member Avatar for Maritimo
0
334

The End.