1 Advanced Programming Examples
using System; class Test { static void Main( string[] args ) { int a = 7; int b = 3; int c = 5; int d = 9; Console.WriteLine(!(d == a) || (a < b+c) && (d-c <= b)); } 2
A factory has some workers and it divides its workers into three skill levels. Unskilled workers receive L.E per hour, semiskilled workers receive L.E an hour, and skilled workers L.E an hour. Write a program to calculate the worker’s weekly pay formatted to two decimal places. Your program input should consist of the hours worked and a skill level indicator for the worker. Then the wage should be displayed.
for (int N = 1; N < 10; N++) { if ( N % 2 == 0) MessageBox.Show (“X”); else if ( N % 3 == 0) MessageBox.Show (“Y”); else MessageBox.Show (“Z”); } MessageBox.Show(“End”);
Write a C program that reads in 30 integer numbers and then print out their sum and average
int a = 5; int b = 10; a = a + 5; { int a; a = 20; b = b + 5 ; } MessageBox.Show(a+ " " + b) } 6
Write a program that reads 100 integer numbers, determines how many positive and negative values have been read, and computes the average of the input values.
The value that printed is int delta = 0, x = 3; if (x / 2 = = 1) delta = delta + x; x - -; if (x / 2 = = 0) delta = delta + x; x - -; MessageBox.Show(delta);
int p, d=4, a=20; if ((d==4) && (a>24)) { p=d+a; MessageBox.Show( “ Low Risk \n ” );} else { p=a-d; MessageBox.Show( “ Low Risk \n ” );} MessageBox.Show( “ the p is = “+ p); Trace
int I = 12, J = 0; while ( I > 8) { I = I -1; J = J + I; } MessageBox.Show( I+”\t”+J);
Trace length = 10; count = 2; while ( count < 5 ) { if ( length >= 10 ) length = length – 2; else length = length * count; count++; } MessageBox.Show( “ The length is ” + length);
int x=2, y=2, k=1; do { y = y * x; MessageBox.Show(“k = k+ “y=“+ y); y = y – k; MessageBox.Show(“k = k+ “y=“+ y); k = k + 1; } while (k < 4);
String a = "alfred"; String b = "fred"; b = "al" + b; if (a == b) a = "fred"; else b = "fred"; 13