Header image  
C Programming  
line decor
  HOME :: BUSINESS :: COMPUTING :: LIFESTYLE :: PASTIME ::
line decor
   
 Programming tutorials in spanish: http://www.tayuda.com/ayudainf/aprendainf/programacion.htm
 
       

Programming in C++

#include
using namespace std;
int main()
{
double radius
double area
double slices
double slicarea
cout << "What is the radius of your pizza?" << endl;
cin >> radius;
area = 3.14 * radius * radius;
cout << "The area of your pizza is: " << area << endl;
cout << "So How many slices do you want?" << endl;
cin >> slices;
slicarea = area / slices
cout << "This is the area of the number of slices you wanted: " <<
slicarea <<endl;

}


double area(double);
double cost(double,double);
double area (double radius)
{
return radius * radius * 3.14;
}
double cost (double area, double price)
{
return price / area;
}
int main()
{
double radius;
double pizza_area;
double price;
double pizza_cost;
cout << "What is the radius of your pizza pie?" << endl;
cin >> radius;
pizza_area = area (radius);
cout << " The area of your pizza is! " << pizza_area << endl;
cout << "What is the total price of your pizza pie?" << endl << endl;
cin >> price;
pizza_cost = cost (pizza_area, price);
cout << "This is the cost per square inch of your pizza" << pizza_cost
<<
endl;
return;
}


 

7-15-92

(instructor bassem jamaleddine)

multiprogramming (trap-supervisor) Systems Languages high level languages such as Pascal and C. Assembly language: applications. manipulate data: how long, what kind of data. integer flow, dluble procedure, char. how to store/retrieve inside memory. I/O binary file. C: 2 weeks, unix: 1 week, Multiprogrammer: 1 week

i.e.

int --> fuction type square -->function type (num) --> argument name

int num; --> argument declaration

{

int answer; --> variable declaration

answer = num * num;

return answer; --> C statement

} --> end of function body

main --> it is a function () --> list of arguments inside the parenthesis of a fuction

{

printf("Welcome to Unix. \n");

}

a C stand-alone program starts with main(). main() is a function along with printf() they both have parenthesis. Inside the brackets {} we list all statements. {S1; S2; S3;...;Sn;} where S is a statement of a function definition.

Printf(): function that has been defined or created for us in the library.

{} Definition of main() function enclosed in brakets.

Expression:

index + 1 --> this is an expression

Index --> a variable = Index + 1; -->expression } all this is a statement --> ++index


7-16-92

HISTORY of C: The programming language C was designed at the Bell Labs as the system language for the Unix operating system. Primarily intended as PDP-11 (a series of 16-bit minicomputers sold by Digital in the 70 & 80's) language. expected (lower case only))

BASICS: main()[no semicolon because it is not a compiled statement]

ASCII file: A text file in which each byte represents one character according to the ASCII code. It is a string of characters. When edit a file you give it a name i.e. test.c if the file contains main() the strings are [m]-[a]-[i]-[n]-[(]-[)]-[-]-[end of file]

c: compiling, linking, loading, interpretation --> basic interpretation

ASCII table - programming interpretation -- inside memory

1 1 1 1 1 1 1 1 = 255
      F       F    
      4       4   0..255=256
                  [0..2n-1] = 2n -----> n = 8 bits

Years ago, to run a program you used a compiler to translate the program into assembly language. Then you used an assembler to translate the assembly language into machine language. Finally, you loaded the machine language into the computer's memory and executed your program.

First the programs tranlated into object modules.

Source program is a set of contained program except that it may require some execution time suport from the supervisor Load-Module is placed into main memory. This may involved some final trasformation of the program to take into consideration. The actual memory location occupied.

Transformation of a source program undergo before final.. goes inside memory in a .. for suitable .. for execution.

source program: [translation] --> [object module]-->[linking]-->[load module]-->[loading]-->[loadedprogram]-->[interpretation]

POINTER: is a variable that contains the address of another variable.

Pointer and arrays are closed related

point: (x, y, z)

pointers

point x

using pointers we can go any where inside memory.

Pointers: It is possible to create pointers to variables C does not have type definitions.

System Language: understandable, readable,readebility, modifiable. reliable vs correcteness.

C has four types modifiers: signed, unsigned, short, long

[8 bits] [8 bits] = 16 bits
1 byte 1 byte 2n= 216
2n=216 [0..216-1  
[0..2n-1] [0..65535] non-negative
[-2n/2 -+2n/2 - 1] vc...0..trc signed
[-32768..+342767] size of (int) is 2 bytes  
int i: i.e. [-32768..+342767]  

Unsigned int i; <=> unsigned i; (If machine has 4 e.g. VM370)

short int (2 bytes) i; <=> short i

long int (8 bytes) i; <=> long i

LOADED PROGRAM:

it is presented as input data to an execution agent, normally (cpu) a hardware processor. The loader will transfer control to the load program, thus causing its execution or interpretation.

commands to execute:

cc acc (new version)

qcc filename.c

tcc

DATA TYPES:

1) Valueless: VOID

4) Scalar Types: INT, CHAR, FLOAT, DOUBLE

2) Compound Types: ARRAYS & STRUCTURES

char, int, long, float, double

size of (char) or size of (integer) --> returns the number of bytes that data occupies.

keword but is an operator, could be user type or variable

sizeof(x) or sizeof x both ways are taking by the compiler however for the type parenthesis are needed sizeof(int)

void, scalar types, aggregate types, arithmetic types, pointers enum, integral types, floating types

80286 1 byte 2 bytes 4 bytes 4 8
803486 1 bytes 4 bytes 8 bytes 8 18

char a; int i; long ii; float r; double rr; | * C (no) as well had a C-type modifier (ANSI)

 

memory

7) - Return to Calling fuction: DET: PC <--pop()

8) - Calling fuction removed the argument

Heap <=> memory

compiler: void * pointer to void

char * replaces

VARIABLES & CONSTANTS ARE:

DATA OBJECTS

PDP-11 (The PDP-11 was a series of 16-bit minicomputers sold by Digital Equipment Corp. in the 1970s and 1980s)

pdp-11


 

P1 [INSERT TEXT FROM FILE P2]

P2 [INSERT PART OF P3 LINES]

P3 [ ]


Visual C++ Programming Tutorial Try for free


Borland C++ 5.5 tutorial


Power point presentation of c++ chapter 15