Posts

Showing posts with the label programming

Using the Copy Assignment Operator to copy objects that have raw pointers.

Listen to this article: https://youtu.be/MdGPC9C5QEI According to cplusplus.com: "A copy constructor is a special constructor for a class/struct that is used to make a copy of an existing instance." The Implicit Copy Constructor      If a copy constructor is not declared, the compiler will use a default one implicitly. The default constructor performs a member-wise copy of the source object. This means that each member is initialized using the corresponding member of the initializer.     Problem: Raw pointers.      If the object contains raw pointers, a member-wise copy may not be appropriate for use. This can cause problems with dangling pointers, double frees, and other undefined behaviour resulting from destructing objects.     Solution: Deep copy.      We explicitly define our own copy constructor when we want to perform a deep copy. That is, instead of copying the pointer, our copy constructor will copy what the po...

C++: Automatic Storage Duration and Static Storage Duration.

Image
https://github.com/pereiradaniel/CPP_CRASH_COURSE/blob/master/P1C4/storage_duration.cpp

C++: Championship Linked List example by adding const correctness, usage...

Image
https://github.com/pereiradaniel/CPP_CRASH_COURSE/blob/master/P1C3/championship_linked_list.cpp

C++: Linked List of F1 World Championships.

Image
https://github.com/pereiradaniel/CPP_CRASH_COURSE/blob/master/P1C3/championship_linked_list.cpp

C: Organizing F1 Team data into structs.

Image

C++: Improving the F1 driver's scoring point system by adding private an...

Image
https://github.com/pereiradaniel/CPP_CRASH_COURSE/blob/master/P1C2/f1points.cpp

Compiling a C program using C and C++ compilers, and a C++ program with ...

Image

CPP Crash Course Review: Overture to C Programmers, and Chapter 1.

A while back I wanted to review the book C++ Crash Course  as a way of making sure I had explored the various facets of C++, but was side-tracked with the learning of other programming languages such as Java . Now I have some time to review my knowledge of these languages, and I want to take this opportunity to refresh my memory of certain concepts, and perhaps even spend time delving into aspects of C++ that I never fully grasped. In my review of the Overture to C Programmers chapter, I did not find anything of of extreme interest. It was mostly a review of the basics of C++, however there were some very competent explanations of some concepts. Probably a bit too much detail if you are somebody already familiar with C, but for those who are new it may be worthwhile. Overall, Chapter 1 made me realize how easily I confuse C with C++ code. This is in part because most well-written C programs are valid C++ programs. Nothing new was learned, but at least I got a chance to set up my ...

My Python Notes.

Started learning Python recently by following this tutorial. Here is a link to my notes, which you may or may not find helpful if you are new to Python. The notes are based on the W3 Schools tutorial that I am doing, and I include my own notes and experiments along with them. https://github.com/pereiradaniel/w3_python/blob/master/notes.md

Java: 3 Easy programs for Class and Objects basics in Java.

Image
Programs: // 1.   Create a class Vehicle. //      a.  The class should have two fields: //          i.  no_of_seats and no_of_wheels. //      b.  Create two objects //          i.  Motorcycle and Car for this class. //      c.  Your output should show the descriptions for Car and Motorcycle package A6 ; class Vehicle {     // Initialize attributes:     int no_of_seats ;     int no_of_wheels ;     // Two-argument constructor:     Vehicle ( int seats , int wheels ) {         no_of_seats   = seats ;         no_of_wheels = wheels ;     }     // Displays values of attributes:     String display () {         return "no_of_seats = " + no_of_seats + ", no_of_wheels = " + no_of_wheels + "." ;     }   ...

C: Convert cm or inches (no functions).

Image
Demonstration of converting cm or inches without using functions. Repl: https://replit.com/@pereiradaniel/Convert-cm-to-inches-function Git repo: https://github.com/pereiradaniel/c_programs/blob/master/metric_imperial_conv/conv2_alt.c  

C: Convert cm and inches using functions.

Image
Demonstration of using functions to convert cm and inches with a main program loop. Some constraints applied to protect against incorrect inputs. Uses a goto statement to emergency exit on wrong input. Repl: https://replit.com/@pereiradaniel/Convert-cm-or-inches-functions Git repo: https://github.com/pereiradaniel/c_programs/blob/master/metric_imperial_conv/conv2.c  

C: Convert cm to inches (no function).

Image
Simple program demonstrating conversion of cm to inches without implementing a function. This is simpler, but your ideal implementation may depend upon a variety of factors requiring your careful consideration. Repl: https://replit.com/@pereiradaniel/Convert-cm-to-inches-no-function Git repo: https://github.com/pereiradaniel/c_programs/blob/master/metric_imperial_conv/conv_alt.c  

C: Convert cm to inches using a function.

Image
Simple program demonstrating one way to convert cm to inches and display the result to the user. Repl: https://replit.com/@pereiradaniel/Convert-cm-to-inches-function Git repo: https://github.com/pereiradaniel/c_programs/blob/master/metric_imperial_conv/conv.c  

C: Decimal/Binary Converter.

Image
A program that converts decimal and binary numbers. Repl: https://replit.com/@pereiradaniel/Dual-BinaryDecimal-Converter Git repo: https://github.com/pereiradaniel/c_programs/blob/master/bin_dec_conv/dual_conversion/dual_conv.c  

C: Decimal to binary conversion with non-recursive function.

Image
Convert a decimal number to binary using a non-recursive function. Repl: https://replit.com/@pereiradaniel/Decimal-to-binary-non-recursive Git repo:  https://github.com/pereiradaniel/c_programs/blob/master/bin_dec_conv/non_recursive/bin_dec_conv.c  

C: Decimal to binary conversion using a recursive function.

Image
Recursive method of decimal to binary conversion. Repl: https://replit.com/@pereiradaniel/Decimal-to-binary-recursive Git repo: https://github.com/pereiradaniel/c_programs/tree/master/bin_dec_conv/recursive  

C: Modify calculator to catch divide by zero error.

Image
Calculator now catches divide by zero error by testing to see if either user inputs are equal to 0, otherwise it executes the division. Repl: https://replit.com/@pereiradaniel/Calculator-Exponent-function-added Git repo: https://github.com/pereiradaniel/c_programs/blob/master/calc/calc4.c  

C: Calculator with exponent function.

Image
Added exponent function to calculator, with improved messages for user. Repl: https://replit.com/@pereiradaniel/Calculator-Exponent-function-added Git repo: https://github.com/pereiradaniel/c_programs/blob/master/calc/calc3.c  

C: Calculator with main loop repeat.

Image
Calculator program now loops until user quits. Repl: https://replit.com/@pereiradaniel/Calculator-Main-loop-added Git repo: https://github.com/pereiradaniel/c_programs/blob/master/calc/calc2.c