Monday, August 22, 2011

Monday 8.22.11

//use the math.h header file, handy for floating-point tests
#include
#include
int main(void)
{
const double ANSWER = 3.14159;
double response;

printf("What is the value of pi?\n");
scanf("%lf", &response);
while (fabs(response - ANSWER) > 0.0001)
{
printf("Try again!\n");
scanf("%lf", &response);
}
printf("Close enough!\n");

return 0;
}


#include
int main(void)
{
long num;
long sum = 0L;
_Bool input_is_good;
printf("Please enter an integer to be summed ");
printf("(q to quit): ");
//the parentheses enclosing the == expression are not needed
//but make the code easier to read
input_is_good = (scanf("%ld", &num) == 1);
while(input_is_good)
{
sum = sum + num;
printf("Please enter next integer (q to quit): ");
input_is_good = (scanf("%ld", &num) == 1);
}
printf("Those integers sum to %ld.\n", sum);

return 0;
}


<#include
int main(void)
{
const int NUMBER = 22;
int count = 1;

while (count <= NUMBER)
{
printf("Be my Valentine!\n");
count++;
}
return 0;

}


#include
int main(void)
{
const int NUMBER = 22;
int count;

for (count = 1; count <= NUMBER; count++)
{
printf("Be my Valentine!\n");
}
return 0;
}


#include
int main(void)
{
const int FIRST_OZ = 37;
const int NEXT_OZ = 23;
int ounces, cost;

printf(" ounces cost\n");
for (ounces=1, cost=FIRST_OZ; ounces <= 16; ounces++, cost += NEXT_OZ)
{
printf("%5d $%4.2f\n", ounces, cost/100.0);
}

return 0;
}



#include
int main(void)
{
const int secret_code = 13;
int code_entered;

do
{
printf("To enter the triskaidekaphobia therapy club, \n");
printf("please enter the secret code number: ");
scanf("%d", &code_entered);
} while (code_entered != secret_code);
printf("Congratulations! You are cured!\n");

return 0;
}


#include
int main(void)
{
const int secret_code = 13;
int code_entered;

do
{
printf("To enter the triskaidekaphobia therapy club, \n");
printf("please enter the secret code number: ");
scanf("%d", &code_entered);
} while (code_entered != secret_code);
printf("Congratulations! You are cured!\n");

return 0;
}


#include
#define ROWS 6
#define CHARS 10
int main(void)
{
int row;
char ch;

for (row = 0; row < ROWS; row++)
{
for (ch = 'A'; ch < ('A' + CHARS); ch++)
{
printf("%c", ch);
}
printf("\n");
}
return 0;
}

here are some vb tutorials


Option Strict On

Public Module TimerFunction
Public Sub Main()
Dim starttime, endtime As Integer
starttime = Environment.TickCount
For ctr As Integer = 0 To 100000000

Next
endtime = Environment.TickCount
Console.WriteLine("Ellapsed time is {0} milliseconds", endtime - starttime)
End Sub
End Module


Module Module1

Dim WithEvents ValueInfo As New Value()

Class Value
Public Event ValueUp(ByVal amount As Double)
Public Event ValueDown(ByVal amount As Double)
Public Event Result(ByVal amount As Double, ByVal announceDate As DateTime)

Public Sub GenerateEvents()
RaiseEvent ValueUp(2)
RaiseEvent ValueDown(-5.5)
RaiseEvent Result(1.25, Now())
End Sub
End Class

Sub PriceGoingUp(ByVal Price As Double)
Console.WriteLine("Up: " & Price)
End Sub

Sub PriceGoingDown(ByVal Price As Double)
Console.WriteLine("Down: " & Price)
End Sub

Sub ResultAnnouncement(ByVal Amount As Double, ByVal AnnounceDate As DateTime)
Console.WriteLine("Result: " & Amount & " " & AnnounceDate)
End Sub


Sub Main()
AddHandler ValueInfo.ValueUp, AddressOf PriceGoingUp
AddHandler ValueInfo.ValueDown, AddressOf PriceGoingDown
AddHandler ValueInfo.Result, AddressOf ResultAnnouncement

ValueInfo.GenerateEvents()
End Sub

End Module


Module Module1

Dim WithEvents ColorInfo As New Color()

Class Color
Public Event ColorChange(ByVal color As String)
Public Event ToneChange(ByVal tone As String)

Public Sub GetColor()
Console.WriteLine("What color?")
Dim newColor = Console.ReadLine()
RaiseEvent ColorChange(newColor)
End Sub

Public Sub GetTone()
Console.WriteLine("What tone?")
Dim newTone = Console.ReadLine()
RaiseEvent ToneChange(newTone)
End Sub


End Class

Sub ColorChanging(ByVal color As String)
Console.WriteLine("Color is now: " & color)
End Sub

Sub ToneChanging(ByVal tone As String)
Console.WriteLine("Tone is now: " & tone)
End Sub

Sub Main()


AddHandler ColorInfo.ColorChange, AddressOf ColorChanging
AddHandler ColorInfo.ToneChange, AddressOf ToneChanging
ColorInfo.GetColor()
ColorInfo.GetTone()

End Sub

End Module


Module Module1
Class DailyJob
Public Event Coding(ByVal Item As String, ByVal StartTime As DateTime)
Public Event Testing(ByVal Item As String, ByVal StartTime As DateTime)
Public Event Meeting(ByVal Item As String, ByVal StartTime As DateTime)

Public Sub GenerateEvents()
RaiseEvent Coding("Coding", Now())
RaiseEvent Testing("Testing", Now().AddMinutes(5.0))
RaiseEvent Meeting("Meeting", Now().AddMinutes(10.0))
End Sub
End Class

Dim WithEvents ThisDailyJob As New DailyJob()

Sub DoJob(ByVal Item As String, ByVal StartTime As DateTime)
Console.WriteLine("Starting " & Item & "at : " & StartTime)
End Sub

Sub Main()
AddHandler ThisDailyJob.Coding, AddressOf DoJob
AddHandler ThisDailyJob.Testing, AddressOf DoJob
AddHandler ThisDailyJob.Meeting, AddressOf DoJob

ThisDailyJob.GenerateEvents()

End Sub

End Module


using System;
using System.Data;

namespace CreateDataColumnAddDataTable
{
class Program
{
static void Main(string[] args)
{
DataTable dt = new DataTable();

//Add the column to the Data Table to create
DataColumn col1 = dt.Columns.Add();
//configure the column -- integer with a default = 0 that
//does not allow nulls
col1.ColumnName = "Column-1";
col1.DataType = typeof(int);
col1.DefaultValue = 0;
col1.Unique = true;
col1.AllowDBNull = false;

//create and configure the column
DataColumn col2 = new DataColumn();
//configure the colum -- string with max length = 50
col2.ColumnName = "Column-2";
col2.DataType = typeof(string);
col2.MaxLength = 50;
//add the column to the DataTable
dt.Columns.Add(col2);

//add a column directly using an overload of the Add()
//method of the DataTable.Columns collection -- the column
//is a string with max length = 50
dt.Columns.Add("Column-3", typeof(string)).MaxLength = 50;

//add multiple existing columns to the DataTable
DataColumn col4 = new DataColumn("Column-4");
//...configure column 4
DataColumn col5 = new DataColumn("Column-5", typeof(int));
//add columns 4 and 5 to the DataTable
dt.Columns.AddRange(new DataColumn[] { col4, col5 });

//Output the columns in the dataTable to the console
Console.WriteLine("DataTable has {0} DataColumns named: ", dt.Columns.Count);
foreach (DataColumn col in dt.Columns)
{
Console.WriteLine("\t{0}", col.ColumnName);
}
Console.WriteLine("\nPress any key to continue.");
Console.ReadKey();
}
}
}


using System;
using System.Data;

namespace CreateDataTableAddDataSet
{
class Program
{
static void Main(string[] args)
{
DataSet ds = new DataSet();

//add a DataTable named Table-1 directly
DataTable dt1 = ds.Tables.Add("Table-1");
//configure the DataTable...add some columns etc.
DataColumn col1 = dt1.Columns.Add();
col1.ColumnName = "PrimaryKey";
col1.DataType = typeof(int);
col1.Unique = true;
col1.AutoIncrement = true;

//add a DataTable named Table-2 by creating the table
//and adding it to the DataSet

DataTable dt2 = new DataTable("Table-2");
//configure the DataTable, add some columns, etc.
DataColumn col2 = new DataColumn();
col2.ColumnName = "CompanyName";
ds.Tables.Add(dt2);
//add multiple DataTables to the DataSet
DataTable dt3 = new DataTable("Table-3");
DataTable dt4 = new DataTable("Table-4");
//configure the DataTable -- add some columns, etc.
ds.Tables.AddRange(new DataTable[] {dt3, dt4});

//output the tables in the DataSet to the console.
Console.WriteLine("DataSet has {0} DataTables named: ", ds.Tables.Count);
foreach (DataTable dt in ds.Tables)
Console.WriteLine("\t{0}", dt.TableName);

Console.WriteLine("\nPress any key to continue.");
Console.ReadKey();
}
}
}

No comments: