User Tools

Site Tools


notes:cprog

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:cprog [2017/08/30 15:01] KJONES35notes:cprog [2018/11/20 08:24] (current) – [Other] sdiarra
Line 1: Line 1:
-======C/C++ Programming Course Notes Wiki======+<WRAP centeralign round box> 
 +<WRAP><color red><fs 200%>Corning Community College</fs></color></WRAP> 
 +<WRAP><fs 150%>CSCS1320 C/C++ Programming</fs></WRAP> 
 +<fs 125%>Course Wiki Page</fs> 
 +</WRAP>
  
-For help with wiki syntax:+======Projects====== 
 +===cci0===
  
-  * [[http://lab46.corning-cc.edu/wiki/syntax|Wiki Syntax]] +===dtr0===
-  * [[https://www.dokuwiki.org/_media/plugin:wrap_plugin_example6.png|Wrap Plugin Syntax]]+
  
 +===sof0===
  
-===25 August===+===dow0===
  
-#include <stdio.h>  +===mbe0===
--This is called a preprocessor directive, it aids the compiler in the early stages of compilation.+
  
-Comments can be added to computer programs to increase their readability. These can take the form of multiline comments which start with /*. This leads the processor to ignore all information until a */ set of tokens is reached.+===cbf0===
  
-<nowiki>//</nowiki> are single line comments, adopted from C++ that allow for short commentsto be make easily.  +===cos0===
  
-All c programs contain the following function: int main()  +===pnc0===
-{+
  
-In this function int is the return value or data type. There are several types of data types, these include char, short int, int,long int and long long int. Main is the name of the function, and the parenthesis following that name indicate that this is indeed a function. A parameter, if a function operates on a certain parameter, could be put inside the parenthesis. +===mbe1===
  
-Programs should end with a return(0); This is a sort of check. If the program returns 0 it is running correctly. +===pnc1===
  
-C understands several logical operators, such as  +===gfo0===
--& or bitwise and which implies that both parts of a given statement are true or the statement is not true.  +
--| or bitwise or which implies that for a statement to be true one part of a given statement must be true.  +
-^ or bitwise exclusive or which implies that for a statement to be true one part of a given statement must be true, but not both.  +
->> is a bitwhise right shift. << is a bitwise left shift. These are useful in multiplying and dividing as a computer is incapable of understanding even basic mathematical operations.  +
-! is a bitwise not. This implies the converse of the following statement.+
  
-<codebasic math operators+===oop0=== 
 +<color #ed1c24>**CALCULATOR::Object-Oriented Programming**</color>
  
-= set equality (thing on right to thing on left) +**Objective**
-+ add +
-- minus +
-mult +
-/ divide +
-% remainder of division (called modulus in some languages) +
-</code>   +
-<code> logical operators+
  
-& bitwise and +The objective of this project is to get a stronger grasp of object-oriented programming, get a better understanding of inheritance, and classes and their properties.
-| bitwise ior (pipe in unix) +
-^ bitwise XOR +
->> bitwise right shift +
-<< bitwise left shift +
-! bitwise not+
  
-logical chaining+**Background**
  
-&& joining and +Over the last few weeks we have covered multiple ways of implementing object oriented model; using the single file method of doing things, and multiple files method of doing things. Using that skill-set, you(we) must implement a program that will replicate the functions of a calculator. 
-|| joining or+ 
 +**Scope** 
 + 
 +For the scope of this project, as long as you implement a program that adopt the object-oriented methodology in C++ - there are no other particular restrictions. 
 + 
 +**Program** 
 + 
 +Replicate the functionality of a calculator, with the ability to accomplish multiple mathematical functions. Given a set of inputs the program must have the capability to compute the numbers based on the functions. 
 + 
 + 
 +======URLs====== 
 +**String Formating(fprintf)** 
 +http://www.cplusplus.com/reference/cstdio/fprintf/ 
 + 
 +**Standard Template Library** 
 +http://www.cplusplus.com/reference/stl/ 
 + 
 + 
 +**Vector Reference** 
 +http://www.cplusplus.com/reference/vector/vector/ 
 +======Notes====== 
 +<color #ed1c24>**TYPEDEF**</color> 
 + 
 + 
 +As a follow to our discussion this week, typedef is a naming convention used in C/C+, its primary use case is to declare various data-types. Defining data types in C can be a tedious task, some data types and variables names only can up to 1/2 of an 80-85char line of code, which ultimately will result in either unreadability, or some very extensive lines. Here is a brief example of how typedef could come in handy. 
 +<code> 
 +unsigned long long int a_very_long_variable_name = some+expressions+here;
 </code> </code>
  
-==How to do Twos Complement== +an optimization for this line would be the following:
-Say you want to do -3. +
-Write positive 3 first:0011 +
-Invert the bits:1100 +
-Add 1:1101 +
-1101 is -3. Will be read as 13 unless you specify it needs to look for a signed value!+
  
 +<code>
 +
 +typedef unsigned long long int ulli_t; 
 +ulli_t a_very_long_variable_name = some+expressions+here; 
 +
 +//much cleaner than the above version(could be better)
 +
 +</code>
 +
 +Although **typedef** appears to be defining only types, it removes some overheads down the road as a developer,it provides consistency, and clarity when used effectively.
 +
 +-------
 +<color #ed1c24>**UNDEF**</color>
 +
 +Undef is a directive in that is available in C and C++. It as the form of #undef when called. Undef is used as a complement to the #define, as a preprocessor directive it is used to enclosed a #define statement to make sure there is no naming conflict and constrict one's logic within a set of code. Let's take a macro for example it is efficient for macros primarily because of the fact that it does common tasks such print, as many modules take have various print functions, the ideal way to make sure there is no conflict is to use undef. This is how it is used:
 +
 +<code>
 +    #define pprintf1() //for pretty-printf
 +    #undef pprintf1()
 +</code>
 +
 +easy peasy! 
 +======Other======
 +-------
 +<color #ed1c24>**Quick Tip:** </color>
 +
 +Recently I have discovered a trick that could help run scripts much quicker with direct access to one's lab46 account, without working only on a single machine at a time. Ultimately, I had to ssh into my account, and whenever I left the terminal open for a few minutes, it would go offline - or had to share scripts between my personal laptop and lab46 machines, and work on projects on one machine at a time(fairly painful). With this method one can easily call commands anywhere, that are otherwise only available on the lab46 account. Here is how it is accomplished: 
 +<code>
 +    system("ssh account@lab47.corning-cc.edu command_here");
 +</code>
 +A working example would be the following:
 +<code>
 +     //From my own laptop
 +     system("ssh user@lab46.corning-cc.edu status cprog")
 +     
 +     //This example would return grades from the user.
 +
 +</code>
 +**Note that the script would prompt you to enter your <color #ed1c24>password</color>.**
notes/cprog.1504119719.txt.gz · Last modified: 2017/08/30 15:01 by KJONES35