Tuesday, April 26, 2011

todTest.cpp

#include
#include
using namespace std;
struct tod
{
int hour;
int minute;
int second;
}; // tod
void printTod(tod& t)
{
cout.fill('0');
cout << setw(2) << t.hour << ':'
<< setw(2) << t.minute << ':'
<< setw(2) << t.second << endl;
cout.fill(' '); // set back to a space
}
int main()
{
tod noon = {12};
printTod(noon);
return 0;
} // main

Thursday, April 14, 2011

C++ bubbleSort

#include
#include
using namespace std;

void bubbleSort1(int* pa, int size)
{
  int* pi = pa;

  // 2 nested for-loops
  for (int i = 0; i < size; i++)
  {
    int* pj = pi+1;
    for (int j = i + 1; j < size; j++)
    {
      if ( *pi > *pj)
      {
        // swap code
        int temp = *pi;
        *pi = *pj;
        *pj = temp;
      } // if
      pj++;
    } // for
    pi++;
  } // for
} // bubbleSort1

void bubbleSort2(int* pa, int size)
{
  for (int i = 0; i < size; i++)
  {
    for (int j = i + 1; j < size; j++)
    {
      if (pa[i] > pa[j])
      {
        // swap code
        int temp = pa[i];
        pa[i] = pa[j];
        pa[j] = temp;
      } // if
    } // for
  } // for
} // bubbleSort2

int main()
{
  const int SIZE = 7;
  int day[] = {8, 44, 33, 55, 908, 39, 88};

  cout << "Unsorted: ";
  int i;
  for (i = 0; i < SIZE; i++)
    cout << day[i] << ' ';
  cout << endl;

  bubbleSort2(day, SIZE);

  cout << "Sorted: ";
  for (i = 0; i < SIZE; i++)
    cout << day[i] << ' ';
  cout << endl;

  return 0;
} // main

Wednesday, April 13, 2011

C++ pointer (step 1)

#include
using namespace std;

int main ()
{
  int *x;
  int c=200;
  x=&c;
  cout << " x is the address of c: " << x << endl;
  cout << " *x points at c: " << *x << endl;
  x++;
  cout << " x is the address of c: " << x << endl;
  cout << " *x points at c: " << *x << endl;
  return 0;
}

C++ pointer (step 2)

#include
using namespace std;

int main ()
{
  int age[5];
  int *p;
  int sum=0;

  p=age;
  for(int i=0;i<5;i++)
  {
    cout << "Enter the age of a student" << endl;
    cin >> *p;
    sum=sum+*p;
    p++;
  }
  p=age;
  cout << "The sum of the ages is : " << sum << endl;
  cout << "The age of the last student is : " << *(p + 4) << endl;
  return 0;
}

C++ pointer (step 3)

#include
using namespace std;

int arrayInputSum(int *pa, int size)
{
  int *pp = pa;
  int sum = 0;
  for(int i=0;i
  {
    cout << "Enter the age of a student" << endl;
    cin >> *pp;
    sum=sum+*pp;
    pp++;
  }
  return sum;
}

int main ()
{
  int age[5];

  int sum = arrayInputSum(age,5);
  cout << "The sum of the ages is : " << sum << endl;

  return 0;
}

Monday, March 21, 2011

lecture 7

Comsc-110 Lecture Topic 1, Programming Concepts






Comsc-100 Lecture 7
Networking

Instructor: Prof. Tony Chern (tchern@dvc.edu)

OSI 7 Layer Reference
Wiki OSI Model 

Media (1-3) Layers
  1. Physical - bit
  2. Link - frame
  3. Network - packet
Host (4-6) Layers
  1. Presentation - segment
  2. Session - data
  3. Transport
Application (7th) Layer 

Advantages p.308-p.309
LAN and WAN to share resources:
  • Peripheral 
  • Storage - Folders and Files
  • Router - Internet Access

Network Architecture
Peer-to-Peer Network: locally managed
Client/Server Network: centrally managedComputer Languages
programs for typing computer code
computer language
  strict, simplified versions of English
strict: spell, case, and puncuate just right
  VISUAL 5
simplified: uses a small set of keywords (100 or so)
  if, while, for, break,... VISUAL 6
Text Editors
Windows XP Notepad VISUAL 7
  with status bar and no wrap
UNIX or Linux vi VISUAL 8
Apple MacOSx TextEdit
avoid RTF editors like WordPad
avoid word processors
  formatting and pagination
Code Editors And IDEs
syntax highlighting, templates,...
JNotePad (avail. from class website) VISUAL 9
many free or inexpensive programs on Internet
interactive development environments (IDEs) VISUAL 10
  built-in code editor
  1-key compiling
  step-by-step debugging
Compilers
convert code into computer program
  code: in .cpp files
    VISUAL 11
  program: in executable files
    VISUAL 12
Elements Of The Language
VISUAL 13: textbook section 1.4.1
statement -- like a sentence
expression -- like a phrase
Sequential Processing
left-to-right in a "line"
lines top-to-bottom
"learning experiences" vs. instructions
  computers follow instructions
  they do not remember relationships
  e.g.: what does area = width * height mean?
Detours!
interuptions in sequential processing
branching: skipping lines
looping: repeating back to a line
subprograms: moving details elsewhere


Watch this space
This space at the end of the lecture notes is used in future lecture notes to include "how to's", with practical examples to help you with your lab assignments. These are not discussed in lectures or in any other written materials for this class, so make sure that you look for them yourself! Here's one now:

How to program
Right-click (or ctrl-click on Apple) here to download and save a brief, introductory PDF!

Friday, November 5, 2010

Puedes Contar conmigo

Un café con sal, ganas de llorar
Mi mundo empezando a temblar
Presiento que se acerca el final
No quiero ganar, ahora eso qué más da
Estoy cansada ya de inventar
Excusas que no saben andar

Y sólo quedarán los buenos momentos de
Ayer que fueron de los dos
Y hoy sólo quiero creer

Que recordarás las tardes de invierno por Madrid
Las noches enteras sin dormir
La vida pasaba y yo sentía que me iba a morir de amor
Al verte esperando en mi portal sentado en el suelo sin pensar
Que puedes contar conmigo

Nunca hubo maldad, sólo ingenuidad
Pretendiendo hacernos creer que
El mundo estaba a nuestros pies
Cuando el sueño venga a por mí
En silencio voy a construir
Una vida a todo color donde vivamos juntos los dos

Y sólo quedarán los buenos momentos de
Ayer que fueron de los dos
Y hoy sólo quiero creer

Que recordarás las tardes de invierno por Madrid
Las noches enteras sin dormir
La vida pasaba y yo sentía que me iba a morir de amor
Al verte esperando en mi portal sentado en el suelo sin pensar
Que puedes contar conmigo para siempre

Y no puedo evitar echarte de menos
Mientras das la mano a mi tiempo y te vas
Yo siento que quiero verte y verte y pienso

Que recordarás las tardes de invierno por Madrid
Las noches enteras sin dormir
La vida pasaba y yo sentía que me iba a morir de amor
Al verte esperando en mi portal sentado en el suelo sin pensar
Que puedes contar conmigo

Que recordarás las tardes de invierno por Madrid
Las noches enteras sin dormir
La vida se pasa y yo me muero, me muero por ti

Sponsored By