Monday, August 15, 2011

Monday 8.15.11


//uses the C preprocessor to define the symbolic constant DENSITY to represent the value 62.4
#include
#include
#define DENSITY 62.4
int main()
{
float weight, volume;
int size, letters;
char name[40]; //name is an array of 40 characters

printf("Hi! What's your first name?\n");
scanf("%s", name);
printf("%s, what's your weight in pounds?\n", name);
scanf("%f", &weight);
size = sizeof name;
letters = strlen(name);
volume = weight / DENSITY;
printf("Well, %s, your volume is %2.2f Cubic feet.\n", name, volume);
printf("Also, your first name has %d letters, \n", letters);
printf("and we have %d bytes to store it in.\n", size);
return 0;
}




#include
#include
#define PRAISE "What a super marvelous name!"
int main(void)
{
char name[40];

printf("What's your name?\n");
scanf("%s", name);
printf("Hello, %s. %s\n", name, PRAISE);
printf("Your name of %d letters occupies %d memory cells.\n", strlen(name), sizeof name);
printf("The phrase of praise has %d letters ", strlen(PRAISE));
printf("and occupies %d memory cells.\n", sizeof PRAISE);

return 0;
}




#include
#define PI 3.14159
int main(void)
{
float area, circum, radius;

printf("What is the radius of your pizza?\n");
scanf("%f", &radius);
area = PI * radius * radius;
circum = 2.0 * PI * radius;
printf("Your basic pizza parameters are as follows:\n");
printf("circumference = %1.2f, area = %1.2f\n", circum, area);
return 0;
}




#include
#include
#include
int main(void)
{
printf("Some number limits for this system:\n");
printf("Biggest int: %d\n", INT_MAX);
printf("Smallest long long: %lld\n", LLONG_MIN);
printf("One byte = %d bits on this system.\n", CHAR_BIT);
printf("Largest double: %e\n", DBL_MAX);
printf("Smallest normal float: %e\n", FLT_MIN);
printf("Float precision = %d digits\n", FLT_DIG);
printf("float epsilon = %e\n", FLT_EPSILON);

return 0;
}




//conversion specifiers
#include
#define PI 3.141593
int main(void)
{
int number = 5;
float espresso = 13.5;
int cost = 31000;

printf("The %d CEOs drank %f cups of espresso.\n", number, espresso);
printf("The value of pi is %f.\n", PI);
printf("Farewell! Thou are too dear for my possessing, \n");
printf("%c%d\n", '$', 2*cost);

return 0;
}




#include
#define PAGES 90
int main(void)
{
printf("*%d*\n", PAGES);
printf("*%2d*\n", PAGES);
printf("*%10d*\n", PAGES);
printf("*%-10d*\n", PAGES);

return 0;
}




#include
#define BLURB "Authentic Imitation!"
int main(void)
{
printf("/%2s/\n", BLURB);
printf("/%24s/\n", BLURB);
printf("/%24.5s/\n", BLURB);
printf("/%-24.5s/\n", BLURB);

return 0;
}





#include
#define PAGES 336
#define WORD 65618
int main(void)
{
short num = PAGES;
short mnum = -PAGES;

printf("num as short and unsigned short: %hd %hu\n", num, num);
printf("-num as short and unsigned short: %hd %hu\n", mnum, mnum);
printf("num as int and char: %d %c\n", num, num);
printf("WORDS as int, short, and char: %d %hd %c\n", WORD, WORD, WORD);

return 0;
}




#include
int main(void)
{
float n1 = 3.0;
double n2 = 3.0;
long n3 = 2000000000;
long n4 = 1234567890;

printf("%.1e %.1e %.1e %.1e\n", n1, n2, n3, n4);
printf("%1d %1d\n", n3, n4);
printf("%1d %1d %1d %1d\n", n1, n2, n3, n4);

return 0;
}
//using an %e specifier does not convert an integer to a floating-point number





using System;
using System.Data.SqlClient;

namespace ChangeConnectionDatabase
{
class Program
{
static void Main(string[] args)
{
string sqlConnectString = @"Data Source=Alfred-PC\SQLExpress;" + "Integrated security=SSPI;Initial Catalog=AdventureWorks;";

using (SqlConnection connection = new SqlConnection(sqlConnectString))
{
Console.WriteLine("ConnectionString = {0}\n", connection.ConnectionString);
//Open the connection
connection.Open();
Console.WriteLine("=> Connection opened.\n");

Console.WriteLine("Connection.State = {0}", connection.State);
Console.WriteLine("Database = {0}\n", connection.Database);

//change the databse
connection.ChangeDatabase("Northwind");
Console.WriteLine("Database changed to Northwind.\n");

Console.WriteLine("Connection.State = {0}", connection.State);
Console.WriteLine("Database = {0}\n", connection.Database);

//close the connection
connection.Close();
Console.WriteLine("=>Connection closed.\n");
Console.WriteLine("Connection.State = {0}", connection.State);
Console.WriteLine("Database = {0}", connection.Database);
}
Console.WriteLine("\nPress any key to continue.");
Console.ReadKey();
}
}
}

No comments: