Anonymous
#include <stdio.h> int main() { int n, c, k, space = 1; printf("Enter number of rows\n"); scanf("%d", &n); space = n - 1; for (k = 1; k <= n; k++) { for (c = 1; c <= space; c++) printf(" "); space--; for (c = 1; c <= 2*k-1; c++) printf("*"); printf("\n"); } space = 1; for (k = 1; k <= n - 1; k++) { for (c = 1; c <= space; c++) printf(" "); space++; for (c = 1 ; c <= 2*(n-k)-1; c++) printf("*"); printf("\n"); } return 0; }
Anonymous
Any simplification to reduce code
Liam
What you mean? First is call the A constructor everytime i know
In A b = B();, C++ will: 1. call the explicitly called default constructor of B, 2. call the copy constructor of A, say A::A(const A&). In the process of 2, the object of B, which is constructed in 1, is passed as the parameter to A::A(const A&) and then, everything declared in B but not in A will be dropped. Since b is an object of the base class A, and does not have enough space to hold all elements of the derived class B.
Liam
B() creates a temp object of the class B, and then passed to the copy cosntructor of A. After the copy constructor is called, the temp object will then be destructed. Please kindly note that, b is an object of the base class A, rather than a pointer or a reference.
Liam
https://stackoverflow.com/questions/274626/what-is-object-slicing FYI.
Anonymous
https://stackoverflow.com/
Anonymous
Super developer site
Liam
#include <iostream> class Base { public: Base() : foo{0} { std::cout << "Default constructor of 'Base' is called." << std::endl; } Base(const Base& orig) : foo{orig.foo} { std::cout << "Copy constructor of 'Base' is called." << std::endl; } Base& operator=(Base& orig) { std::cout << "Copy assignment of 'Base' is called." << std::endl; this->foo = orig.foo; return *this; } virtual ~Base() {} private: size_t foo = 0; }; class Derived : public Base { public: Derived() : Base(), bar{0} { std::cout << "Default constructor of 'Derived' is called." << std::endl; } private: size_t bar = 0; }; int main() { Base derived = Derived(); return 0; } Gives the following result:
Liam
Francesco
@LiamHuang Thx m8
Liam
In this snippet of code, derived is an object of the Base class, and hence has no member data named bar. However, calling Derived() creates a temp object of Derived, which, of course, has a member data named bar. In the copy constructor of Base, bar in the temp object of Derived is dropped. And we called this crop or slice.
Liam
Any simplification to reduce code
Here is a clue I could give you: every symmetry cause an abs(). good luck
Liam
Any simplification to reduce code
Since this looks like a homework, I'll not give you the answer directly. However, I have a more complex version of the plotting code. #include <stdio.h> const int w = 23; const int h = 12; int triangle(int x, int y) { return abs(x) <= y; } int f(int x, int y) { return triangle(x - 11, y) && triangle((x + y / 3 * 3 + 3) % 6 - 2, y % 3); } int main() { int x, y; for (y = 0; y < h; y++) { for (x = 0; x < w; x++) printf(f(x, y) ? "* " : " "); puts(""); } } Enjoy.
Liam
Anonymous
hey guys
Anonymous
c++ how game?
Anonymous
how to make game 3d?
Isc
opengl
Francesco
c++ how game?
Unreal if you want a game engine. You can do also with sfml (and opengl as already suggest)
Liam
Hmmm, if you have enough basic mathematics knowledge, You could draw static 3D figures by pure C/C++ codes.
Liam
Liam
For example, I draw this figure by pure C codes. (light refraction in a glass M shape)
Liam
lol
Liam
However, for game programming, a game engine is required.
Liam
Opengl?
Nope, just math.h, stdlib.h, some mathematics calculation and of course a plotting library (just for saving figures).
Francesco
Ah, cool
Francesco
How much time take to create this image?
Liam
I don't know... It's a secondary product of a major project.
Liam
Hard to estimate...
Liam
lower the sample number. (Monte Carlo integration)
Anonymous
who can help me
Anonymous
please
Anonymous
in c programming enter n and show this number n power or not of 3 and which power without multyple and devide ways only if else and for
AndrEEa
in c programming enter n and show this number n power or not of 3 and which power without multyple and devide ways only if else and for
1) make a division function using sub (-) 2) loop division by 3 of the number and count the iterations while the numbers is >=3 if it begins equal 3 it's a power of 3 else not and the iteration count is the exponent n
Anonymous
please
AndrEEa
nope
Anonymous
please
Anonymous
help me
Anonymous
what's this?
AndrEEa
what's this?
adaptive filter diagram
Anonymous
Hello guys
Anonymous
do you have hack channels
Anonymous
premium account?
Anonymous
Hi there
Anonymous
I really really want to learn programming language But unfortunately there is no course or any center in my town to learn Can you tell me where to start plz
Anonymous
I really really want to learn programming language But unfortunately there is no course or any center in my town to learn Can you tell me where to start plz
hey there, you can simply learn from internet and books + practice and dedication, but before beginning on writing code i would suggest to learn how to have a right mindset and about "problem solving", simply because alot of people think about remembering the syntax but don't know what the tool (code) they have does, and don't know how to assemble everything together to create what you want
Anonymous
lemme find a good beginner book on c++ for ya
k1k3
hi
Anonymous
also, before starting ( i assume you are on windows ) install visual studio 17 https://youtu.be/39IsItNIoQs follow this video until it installed
Anonymous
if you need help write your problem here or just pm me
Anonymous
hi
Hello, welcome
Anonymous
glad someone one here stated right approach for mastering things
i see alot of people focusing on syntax and memorizing it, they soon get confused if you ask to create something different with the same tools (even simple stuff)
Anonymous
Thank you again ☺️☺️
no problem lad, always here to help
Anonymous
Also guys, if you need a book just ask and i will send it
Григорий
Hello, guys. Is anyone working on MacBook in Sublime? Could you say how to compile my code there?
Anonymous
Hello, guys. Is anyone working on MacBook in Sublime? Could you say how to compile my code there?
use gcc, you can compile via terminal, compile via integrated sublime terminal or there should be some ways to make compilation within the editor (somewhere in the lines of make and cmake i guess)
Anonymous
I have one year left before graduation..AT THE end of 2018 i am supposed to make a mobile application as a graduation project..will i be able to learn java in summer?
Anonymous
and already knowing c++ is really helpfull
Anonymous
Thank u
Anonymous
😌
Anonymous
one thing different is the input, you need to manually cast a string ex. int x = Integer.parseInt(s); // needs to be in a try catch or // need to throw IOException
Anonymous
the rest is similar to c++, output is made with a function within an object within a Class (System.out.println if you wanna go new line at the end or System.out.print if you dont want to) if, while, do while, for and switch case are the same as c++ variables are almost equals (except boolean instead of bool and arrays are defined a bit differently) main in a method (function) inside a class classes have same idea but a bit different syntax,for example.you have to tell each attribute and method if it's public, protected or private and methods are defined within the class after the prototype
Anonymous
and everything has to be within a class
Anonymous
this is a sum up of what to expect with java
Anonymous
and in methods if you parse a primitive variable its parsed by value, and an object or array by reference
Anonymous
objects and arrays (arrays are objects) are parsed by reference
Anonymous
try modifying an external object within a method
Anonymous
it modifies it
Anonymous
strange, with me it worked parse by reference
Anonymous
https://www.google.it/url?sa=t&source=web&rct=j&url=https://www.javaworld.com/article/2077424/learn-java/does-java-pass-by-reference-or-pass-by-value.amp.html&ved=0ahUKEwiQueDbmfbXAhVEXBoKHSwtAJ0QFgg4MAM&usg=AOvVaw2lU7FetN_b1451EFANOMwo&ampcf=1
Anonymous
in fact
Anonymous
it copies the reference