while
for
do-while
syntactic sugar
conditionals
a == b
a != b
!( a == b)
a < b
a > b
a >= b
a <= b
|| OR
&& AND
a = 5;
b = 2;
if (a == b || c == d)
c = 6;
if (a < c < b)
if (a < c && c < b)
{
infinite loop
int i = 0, j =0;
while (i < 10)
{
cout << "Hello" << endl;
j++;
}
sum of the numbers from 1 to 50
FOR LOOP
for (int i = 0; i < 10; i++)
{
cout << "Hello!\n";
}
Tuesday, July 6, 2010
Thursday, July 1, 2010
Wednesday, June 30, 2010
// candyweight.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
using namespace std;
int main()
{
cout << setw(4) << 5 << endl;
cout << setw(4) << 25 << endl;
double pay;
pay = 10.50 * 23.333;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "The pay is $" << pay << endl;
// declare and initialize our variable
int numBars;
numBars=0;
double barWeight = 0;
cout << "Please enter # of bars & weight of 1 bar: ";
cin >> numBars >> barWeight;
// this is a comment!
cout << "\a\a\a\"Total weight is " << numBars * barWeight << endl;
cout << "Please enter # of bars & weight of 1 bar for another brand: ";
cin >> numBars >> barWeight;
cout << "Total weight is " << numBars * barWeight << "\n";
return 0;
}
data type
4 int
4 long int
4.6 float
4.6 double
4.6 long double
"Josh" string
true bool
'x' char
unsigned
signed
long
short
pico hello.cpp
g++ hello.cpp
./a.out
int numpods, peasperpod, total;
double temp;
string name;
hw:
write a prog.
variables: one, two, three, four, five
data type double
1.000, 1.414, 1.732, 2.000, 2.236
N Square Root
1 1.000
2 1.414
3 1.732
4 2.000
5 2.236
//
#include "stdafx.h"
#include
#include
using namespace std;
int main()
{
cout << setw(4) << 5 << endl;
cout << setw(4) << 25 << endl;
double pay;
pay = 10.50 * 23.333;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "The pay is $" << pay << endl;
// declare and initialize our variable
int numBars;
numBars=0;
double barWeight = 0;
cout << "Please enter # of bars & weight of 1 bar: ";
cin >> numBars >> barWeight;
// this is a comment!
cout << "\a\a\a\"Total weight is " << numBars * barWeight << endl;
cout << "Please enter # of bars & weight of 1 bar for another brand: ";
cin >> numBars >> barWeight;
cout << "Total weight is " << numBars * barWeight << "\n";
return 0;
}
data type
4 int
4 long int
4.6 float
4.6 double
4.6 long double
"Josh" string
true bool
'x' char
unsigned
signed
long
short
pico hello.cpp
g++ hello.cpp
./a.out
int numpods, peasperpod, total;
double temp;
string name;
hw:
write a prog.
variables: one, two, three, four, five
data type double
1.000, 1.414, 1.732, 2.000, 2.236
N Square Root
1 1.000
2 1.414
3 1.732
4 2.000
5 2.236
Tuesday, June 29, 2010
assignment 1
1) write a prog which asks
for # of quarters, dimes,
and nickels. output total
value in cents
2)
distance = (acceleration X time^2)/2
prompt for: time in seconds
output: how far it would drop
there is constant acceleration of 32ft per second
for # of quarters, dimes,
and nickels. output total
value in cents
2)
distance = (acceleration X time^2)/2
prompt for: time in seconds
output: how far it would drop
there is constant acceleration of 32ft per second
Monday, June 28, 2010
Lecture 1
111 Algorithmic Problem Solving
program in C++
1 midterm, 1 final -- 70%, weighted toward the better score
labs -- 30%
1) C++ without fear
2) * Savitch
3) Schaum's outline programming with C++
von Neumann architecture
sequential access memory vs.
random access memory
scroll vs.
book
vhs tape vs. dvd
ram vs. disk
1. ask for a number
2. read in a #, call it x
3. ask for a number
4. read in a #, call it y
5. add x and y, put it in z
6. print out z
7. go to step 1
fetch-execute cycle
IP: 1
fetch an instruction from RAM, put it into the ALU
the ALU will execute the instruction
update the IP
fetch instruction....
computers only understand binary
0100100
10010010010010001110
machine language
assembly language
MOV AX, 6
ADD AX, 5
SUB BX, AX
MOV is 1001001
AX is 0001
BX is 1100
SUB is 10010
C++. closer to english
interpreted language
compiled language
main()
{
int x, y, z;
cin >> x >> y;
z = x+y;
cout << z << endl;
}
venus
1. edit the source code
2. compile it
3. run it
IDE
integrated development environment
Microsoft Visual Studio
www.microsoft.com/express
program in C++
1 midterm, 1 final -- 70%, weighted toward the better score
labs -- 30%
1) C++ without fear
2) * Savitch
3) Schaum's outline programming with C++
von Neumann architecture
sequential access memory vs.
random access memory
scroll vs.
book
vhs tape vs. dvd
ram vs. disk
1. ask for a number
2. read in a #, call it x
3. ask for a number
4. read in a #, call it y
5. add x and y, put it in z
6. print out z
7. go to step 1
fetch-execute cycle
IP: 1
fetch an instruction from RAM, put it into the ALU
the ALU will execute the instruction
update the IP
fetch instruction....
computers only understand binary
0100100
10010010010010001110
machine language
assembly language
MOV AX, 6
ADD AX, 5
SUB BX, AX
MOV is 1001001
AX is 0001
BX is 1100
SUB is 10010
C++. closer to english
interpreted language
compiled language
main()
{
int x, y, z;
cin >> x >> y;
z = x+y;
cout << z << endl;
}
venus
1. edit the source code
2. compile it
3. run it
IDE
integrated development environment
Microsoft Visual Studio
www.microsoft.com/express
Monday, May 17, 2010
1) what include file do I need?
2) what data types are available
3) how do i declare?
4) how do i use
1)
#include // for cin and cout
#include // for file io
2)
ifstream
ofstream
these are data types, just like int, double, string
3)
ifstream jin;
ofstream jout;
alternatively:
ifstream jin("hello.txt");
ofstream jout("myoutput.txt");
4)
open a file:
jin.open("hello.txt");
jout.open("myoutput.txt");
close a file:
jin.close();
jout.close();
read from a file:
int x;
jin >> x;
write to a file:
jout << x << "hello" << endl;
2) what data types are available
3) how do i declare?
4) how do i use
1)
#include
#include
2)
ifstream
ofstream
these are data types, just like int, double, string
3)
ifstream jin;
ofstream jout;
alternatively:
ifstream jin("hello.txt");
ofstream jout("myoutput.txt");
4)
open a file:
jin.open("hello.txt");
jout.open("myoutput.txt");
close a file:
jin.close();
jout.close();
read from a file:
int x;
jin >> x;
write to a file:
jout << x << "hello" << endl;
Wednesday, May 12, 2010
What you should perhaps be able to do, come CS211
http://venus.cs.qc.cuny.edu/~alayev
http://venus.cs.qc.cuny.edu/~waxman/211
http://venus.cs.qc.edu/~joshwaxman/Spring2009/cs211
Project 1:
Do things with one-dimensional arrays -- the arrays you know and love. Namely, do the following, in separate programs:
a) Set all the elements of the array to the value 5.
b) Print out all the values of the array, separated by the comma character. There should not be a trailing comma character.
c) Create a string containing all the elements of the array, separated by the comma character.
d) Find the product of all the elements in the array.
e) Find the sum of all elements in the array.
f) Find the minimum value in the array.
g) Find the maximum value in the array.
h) Find the position of the minimum element in the array.
i) Here is a Wikipedia page which has pseudocode for the merge algorithm, which will merge two sorted arrays into a third sorted array.
http://en.wikipedia.org/wiki/Merge_algorithm
Implement it in C++.
j) Fill two arrays (A and B) with items typed in from the keyboard, add up the elements in each position, and store the result in the corresponding spot in array C. Thus, C[6] would contain A[6] + B[6].
k) Read in a bunch of numbers into an array from a file, and then Bubble-sort them.
http://en.wikipedia.org/wiki/Bubble_sort
l) Now that you can find the position of the minimum element in an array (see h), implement the Selection sort:
http://en.wikipedia.org/wiki/Selection_sort
m) Write some code which will reverse an array.
o) Write some code which will read a file containing integers in the range of 0 to 100, and then output the frequency of each element in the file.
p) Write a recursive function which will print out every element in an array. It should take in the array, the position to print out, and the capacity.
(optional q) There is a programming language known as C# (pronounced see-sharp), which is quite similar to C++. Teach yourself some C#, and implement items (a) through (p) in C#.
r) Read up about the goto statement, and write a program which will print "this program is making me dizzy" forever.
http://venus.cs.qc.cuny.edu/~waxman/211
Lab 1:
Make teams of 3 people.
Come up with a cool name.
Register your team name together with list of members.
We will learn how to log in to the computers, how to run Visual Studio. Submit with this first project digital photos of your team members so that I can keep track of you. Submission will be by making a Google Document, and sharing it with me. If you do not finish in lab, you can finish it for homework.http://venus.cs.qc.edu/~joshwaxman/Spring2009/cs211
Project 1:
Do things with one-dimensional arrays -- the arrays you know and love. Namely, do the following, in separate programs:
a) Set all the elements of the array to the value 5.
b) Print out all the values of the array, separated by the comma character. There should not be a trailing comma character.
c) Create a string containing all the elements of the array, separated by the comma character.
d) Find the product of all the elements in the array.
e) Find the sum of all elements in the array.
f) Find the minimum value in the array.
g) Find the maximum value in the array.
h) Find the position of the minimum element in the array.
i) Here is a Wikipedia page which has pseudocode for the merge algorithm, which will merge two sorted arrays into a third sorted array.
http://en.wikipedia.org/wiki/Merge_algorithm
Implement it in C++.
j) Fill two arrays (A and B) with items typed in from the keyboard, add up the elements in each position, and store the result in the corresponding spot in array C. Thus, C[6] would contain A[6] + B[6].
k) Read in a bunch of numbers into an array from a file, and then Bubble-sort them.
http://en.wikipedia.org/wiki/Bubble_sort
l) Now that you can find the position of the minimum element in an array (see h), implement the Selection sort:
http://en.wikipedia.org/wiki/Selection_sort
m) Write some code which will reverse an array.
o) Write some code which will read a file containing integers in the range of 0 to 100, and then output the frequency of each element in the file.
p) Write a recursive function which will print out every element in an array. It should take in the array, the position to print out, and the capacity.
(optional q) There is a programming language known as C# (pronounced see-sharp), which is quite similar to C++. Teach yourself some C#, and implement items (a) through (p) in C#.
r) Read up about the goto statement, and write a program which will print "this program is making me dizzy" forever.
Subscribe to:
Posts (Atom)