C# program
a) Manipulating the Form’s properties. Change the Font property to 9pt Segoe UI. Change the Form’s Text property to Radio and the Size to 427, 194.
b) Adding the Pre-set Stations GroupBox and Buttons. Set the GroupBox’s Size to 180, 55 and its Text to Pre-set Stations. Add six Buttons to the GroupBox. Set each one’s Size to 23, 23. Change the Buttons’ Text properties to 1, 2, 3, 4, 5, 6, respectively.
c) Adding the Speakers GroupBox and CheckBoxes. Set the GroupBox’s Size to 120, 55 and its Text to Speakers. Add two CheckBoxes to the GroupBox. Set the Text properties for the CheckBoxes to Rear and Front.
d) Adding the Power On/Off Button. Add a Button to the Form. Set its Text to Power On/ Off and its Size to 75, 55.
e) Adding the Volume Control GroupBox, the Mute CheckBox and the Volume TrackBar. Add a GroupBox to the Form. Set its Text to Volume Control and its Size to 180, 70. Add a CheckBox to the GroupBox. Set its Text to Mute. Add a TrackBar to the GroupBox.
f) Adding the Tuning GroupBox, the radio station Label and the AM/FM RadioButtons. Add a GroupBox to the Form. Set its Text to Tuning and its Size to 120, 70. Add a Label to the GroupBox. Set its AutoSize to False, its Size to 50, 44, its BackColor to Black, its ForeColor to Silver, its font to 12pt bold and its TextAlign to MiddleCenter. Set its Text to 92.9. Place the Label as shown in the figure. Add two RadioButtons to the GroupBox. Set the Text of one to AM and of the other to FM.
g) Adding the image. Add a PictureBox to the Form. Set its BackColor to PeachPuff, its SizeMode to StretchImage and its Size to 55, 70. Set the Image property to Music- Note.gif (located in the examples folder for Chapter 2).
Part 2: Console applications.
1. Write C# program to display welcome to C# programming
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("welcome to");
Console.WriteLine("C# programming");
}
}
}
2.Write C# program to Calculating the product of three integers.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Variable Declaration
int x; // stores first number to be entered by user
int y; // stores second number to be entered by user
int z; // stores third number to be entered by user
int result; // product of numbers
//****************End variable declaration
Console.Write( "Enter first integer: " ); // prompt for input
x = Convert.ToInt32( Console.ReadLine() ); // read first integer
Console.Write( "Enter second integer: " ); // prompt for input
y = Convert.ToInt32( Console.ReadLine() ); // read second integer
Console.Write( "Enter third integer: " ); // prompt for input
z = Convert.ToInt32( Console.ReadLine() ); // read third integer
result = x * y * z; // calculate the product of the numbers
Console.WriteLine( "Product is {0}", result );
}// end Main
}
}
Enum Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int Sunday = 0;
int Monday = 1;
int Tuesday = 2;
int Wednesday = 3;
int Thursday = 4;
int Friday = 5;
int Saturday = 6;
System.Console.WriteLine(Sunday);
System.Console.WriteLine(Monday);
System.Console.WriteLine(Tuesday);
System.Console.WriteLine(Wednesday);
System.Console.WriteLine(Thursday);
System.Console.WriteLine(Friday);
System.Console.WriteLine(Saturday);
}// end Main
}
}
Output
0
1
2
3
4
5
6
Using Enum
namespace ConsoleApplication1
{
class Program
{
enum WeekDays
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
static void Main(string[] args)
{
System.Console.WriteLine(WeekDays.Sunday);
System.Console.WriteLine(WeekDays.Monday);
System.Console.WriteLine(WeekDays.Tuesday);
System.Console.WriteLine(WeekDays.Wednesday);
System.Console.WriteLine(WeekDays.Thursday);
System.Console.WriteLine(WeekDays.Friday);
System.Console.WriteLine(WeekDays.Saturday);
}// end Main
}
}
Output
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
namespace ConsoleApplication1
{
class Program
{
enum WeekDays
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
static void Main(string[] args)
{
System.Console.WriteLine((int)WeekDays.Sunday);
System.Console.WriteLine((int)WeekDays.Monday);
System.Console.WriteLine((int)WeekDays.Tuesday);
System.Console.WriteLine((int)WeekDays.Wednesday);
System.Console.WriteLine((int)WeekDays.Thursday);
System.Console.WriteLine((int)WeekDays.Friday);
System.Console.WriteLine((int)WeekDays.Saturday);
}// end Main
}
}
Output
0
1
2
3
4
5
6
3. Application that determines the larger of two numbers.
(Comparing Integers) Write an application that asks the user to enter two integers, obtains
them from the user and displays the larger number followed by the words "is larger". If the numbers
are equal, display the message "These numbers are equal." Use the techniques shown in Fig. 3.26.
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int number1; // first number to compare
int number2; // second number to compare
// prompt for input and read first number
Console.Write( "Enter first integer: " );
number1 = Convert.ToInt32( Console.ReadLine() );
// prompt for input and read second number
Console.Write( "Enter second integer: " );
number2 = Convert.ToInt32( Console.ReadLine() );
// determine whether number1 is greater than number2
if ( number1 > number2 )
Console.WriteLine( "{0} is larger", number1 );
// determine whether number1 is less than number2
if ( number1 < number2 )
Console.WriteLine( "{0} is larger", number2 );
// determine whether number1 is equal to number2
if ( number1 == number2 )
Console.WriteLine( "These numbers are equal" );
} // end Main
}
}
Output
Enter first integer: 10
Enter second integer: 12
12 is larger
Enter first integer: 12
Enter second integer: 10
12 is larger
Enter first integer: 11
Enter second integer: 11
These numbers are equal