Wednesday, August 17, 2011

Wednesday 8.17.11

using System;
using System.IO;

public class MainClass
{
public static void Main()
{
FileInfo MyFile = new FileInfo(@"C:\inetpub\Test2.txt");
MyFile.Create();
}
}




using System;
using System.IO;

public class MainClass
{
public static int Main(string[] args)
{
FileInfo f = new FileInfo(@"C:\inetpub\test3.txt");
FileStream fs = f.Create();

Console.WriteLine("Creation: {0}", f.CreationTime);
Console.WriteLine("Full name: {0}", f.FullName);
Console.WriteLine("Full atts: {0}", f.Attributes.ToString());

fs.Close();
f.Delete();

return 0;
}
}


using System;
using System.IO;

public class MainClass
{
static void Main(string[] args)
{
FileInfo MyFile = new FileInfo(@"C:\inetpub\Testing3.txt");

MyFile.Delete();
}
}



using System;
using System.IO;

class MainClass
{

static void createFile()
{
FileInfo MyFile = new FileInfo(@"C:\inetpub\inputFile.txt");
MyFile.Create();
}

public static void Main(string[] args)
{

int i;
FileStream fin;
FileStream fout;



try
{
fin = new FileStream(@"C:\inetpub\inputFile.txt", FileMode.Open);
}
catch (FileNotFoundException exc)
{
Console.WriteLine(exc.Message + "\nInput File Not Found");
Console.WriteLine("Creating file now.");
createFile();
return;
}

try
{
fout = new FileStream(@"C:\inetpub\outputFile.txt", FileMode.Create);
}
catch (IOException exc)
{
Console.WriteLine(exc.Message + "\nError Opening Output File");
return;
}

try
{

do
{
i = fin.ReadByte();
if (i != -1)
{
fout.WriteByte((byte)i);
}
} while (i != -1);
}
catch (IOException exc)
{
Console.WriteLine(exc.Message + " File Error");
}

fin.Close();
fout.Close();
}
}



using System;
using System.IO;

class MainClass
{
public static void Main()
{
string[] aFiles = Directory.GetFiles(@"C:\inetpub\");

foreach (string s in aFiles)
{
Console.WriteLine(s);
}
}
}

OK, back to C. Classes start next week!


#include
int main(void)
{
int bph2o = 212;
int rv;

rv = printf("%d F is water's boiling point.\n", bph2o);
printf("The printf() function printed %d characters.\n", rv);
return 0;
}




#include
int main(void)
{
printf("Here's one way to print a ");
printf("long string.\n");
printf("Here's another way to print a \ long string.\n");
printf("Here's the newest way to print a "
"long string.\n");
return 0;
}




#include
int main(void)
{
unsigned width, precision;
int number = 256;
double weight = 242.5;

printf("What field width?\n");
scanf("%d", &width);
printf("The number is : %d:\n", width, number);
printf("Now enter a width and a precision:\n");
scanf("%d %d", &width, &precision);
printf("Width = %*.*f\n", width, precision, weight);
printf("Done!\n");

return 0;
}




#include
#define ADJUST 7.64
#define SCALE 0.325
int main(void)
{
double shoe, foot;

printf("Shoe size (men's) foot length\n");
shoe = 3.0;
while (shoe < 18.5)
{
foot = SCALE*shoe + ADJUST;
printf("%10.1f %15.2f inches\n", shoe, foot);
shoe = shoe + 1.0;
} //end while
printf("If the shoe fits, wear it.\n");

return 0;
}




#include
int main(void)
{
int num = 1;
while (num < 21)
{
printf("%4d %6d\n", num, num * num);
num = num + 1;
}
}




#include
#define SQUARES 64
#define CROP 1E15
int main(void)
{
double current, total;
int count = 1;

printf("square grains total ");
printf("fraction of \n");
printf(" added grains ");
printf("US total\n");
total = current = 1.0; //start with one grain
printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total/CROP);
while (count < SQUARES)
{
count = count + 1;
current = 2.0 * current;
total = total + current;
printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total/CROP);
}
printf("That's all.\n");

return 0;
}




#include
int main(void)
{
printf("integer division: 5/4 is %d \n", 5/4);
printf("integer division: 6/3 is %d \n", 6/3);
printf("integer division: 7/4 is %d \n", 7/4);
printf("floating division: 7./4. is %1.2f \n", 7./4.);
printf("mixed division: 7./4 is %1.2f \n", 7./4);

return 0;
}




#include
int main(void)
{
int n = 0;
size_t intsize;
intsize = sizeof (int);
printf("n = %d, n has %zd bytes; all ints have %zd bytes.\n", n, sizeof n, intsize);

return 0;
}




#include
#define SEC_PER_MIN 60
int main(void)
{
int sec, min, left;

printf("Convert seconds to minutes and seconds!\n");
printf("Enter the number of seconds (<=0 to quit:\n);
scanf("%d", &sec);
while (sec > 0)
{
min = sec / SEC_PER_MIN;
left = sec % SEC_PER_MIN;
printf("%d seconds is %d minutes, %d seconds.\n", sec, min, left);
printf("Enter next value (<=0 to quit:\n");
scanf("%d", &sec);
}
printf("Done!\n");
return 0;
}




#include
#define MAX 100
int main(void)
{
int count = MAX +1;
while(--count > 0) {
printf("%d bottles of beer on the wall, "
"%d bottles of beer!\n", count, count);
printf("Take one down and pass it around, \n");
printf("%d bottles of beer~\n\n", count - 1);
}

return 0;
}

No comments: