C# Program Compilation
C# Program Compilation
A Compilation Project
By:
John Rick Valle
Emmanuel Veloso
In partial fulfillment
of the Requirements for the Subject ITC111 Computer Programming 1
November 2024
0
TABLE OF CONTENTS
1
Program 1: Printing Char, String, Integer, Float, and Double.
Description of the program: Program will display “Char, String, Integer, Float, and Double.”
using System;
2
Flowchart.
3
Program 2: Using comments and Naming Conventions.
Description of the program: Program will display “Char, String, Integer, Float, and Double.”
using System;
4
Flowchart.
5
Program 3: Arithmetics in C#
Description of the program: Program displays basic arithmetic operations on a set of predefined
numbers.
using System;
6
Flowchart.
7
Program 4: Escape Sequence
Description: Program displays three different sentences using Console.WriteLine without using
variables
using System;
8
Flowchart.
9
Program 5: Comparing Numbers.
Description: Program displays the biggest and smallest using the if-else if- else, comparison,
and logical operators.
using System;
10
biggestNumber = num2;
}
else
{
biggestNumber = num3;
}
11
Flowchart.
12
13
Program 6: Age group
Description: Program displays the age group based on what age(number/integer) the user has
inputted.
using System;
do
{
try
{
Console.Write("Enter Age: "); // Prompt the user for input
string userInput = Console.ReadLine(); // Read the input from the user
else
{
// Determine the age group based on the entered age
switch (age)
{
case int userAge when (userAge >= 0 && userAge <= 6):
Console.WriteLine("Age group: Toddler");
break;
14
case int userAge when (userAge >= 7 && userAge <= 12):
Console.WriteLine("Age group: Kid");
break;
case int userAge when (userAge >= 13 && userAge <= 19):
Console.WriteLine("Age group: Teen");
break;
case int userAge when (userAge >= 20 && userAge <= 30):
Console.WriteLine("Age group: Young Adult");
break;
case int userAge when (userAge >= 31 && userAge <= 59):
Console.WriteLine("Age group: Adult");
break;
case int userAge when (userAge >= 60):
Console.WriteLine("Age group: Senior");
break;
default:
Console.WriteLine("Invalid input.");
Break;
}
}
Flowchart.
15
Program 7: Printing an Array
16
Description: Program displays the student information inside a 2D array.
using System;
Console.WriteLine("Activity 7: \n");
17
Flowchart.
18
Program 8: Math Methods.
Description: Program displays four Methods for Math (Addition, Subtraction, Multiplication, &
Division).
using System;
Console.WriteLine("Activity 8:");
while (true)
{
int firstNumber = 0;
int secondNumber = 0;
19
while (true)
{
Console.WriteLine("\nOptions:");
Console.WriteLine("Add - Addition");
Console.WriteLine("Sub - Subtraction");
Console.WriteLine("Mul - Multiplication");
Console.WriteLine("Div - Division");
Console.Write("\nPlease select an Option: ");
string operationChoice = Console.ReadLine().ToLower();
Console.WriteLine("\nOptions:");
Console.WriteLine("Add - Addition");
Console.WriteLine("Sub - Subtraction");
Console.WriteLine("Mul - Multiplication");
Console.WriteLine("Div - Division");
}
}
20
Flowchart.
21
22
Prelim exam
public void PrelimExam()
{
Console.WriteLine("Prelim Exam:");
Console.WriteLine("JOHN RICK VALLE" + " " + 21 + " " + 'M');
Console.WriteLine("EMMANUEL VELOSO" + " " + 19 + " " + 'M');
}
23
Midterm exam
24
// Display the standard time with appropriate format
if (militaryTime % 100 < 10)
{
// For minutes less than 10, add a leading zero
Console.WriteLine("It is " + hours + ":0" + (militaryTime % 100) + period + " standard
time");
}
else
{
// Display the standard time without a leading zero for minutes
Console.WriteLine("It is " + hours + ":" + (militaryTime % 100) + period + " standard
time");
}
}
else if (militaryTime == 0)
{
// Special case for midnight
Console.WriteLine("It is 12 AM standard time");
}
else if (militaryTime <= 59 && militaryTime > 0)
{
// Special case for times between 00:01 and 00:59
Console.WriteLine("It is 12:" + militaryTime + " AM standard time");
}
else
{
// If the input time is not valid, display an error message
Console.WriteLine("Invalid Time");
}
}
25
Semi-final exam
public void SemiFinalExam()
{
Console.WriteLine("Semi Final Exam:");
bool isContinueProgram = true; // Initialize the loop control variable
while (isContinueProgram)
{
// Display the menu options
Console.WriteLine("1. Rectangle");
Console.WriteLine("2. Triangle");
Console.WriteLine("3. Pyramid");
Console.WriteLine("4. Exit");
Console.Write("Choose your shape: ");
26
}
Console.WriteLine(); // Move to the next line after each row
}
break;
case 2:
// Handle triangle drawing
Console.Write("Input your height: ");
int triangleHeight = int.Parse(Console.ReadLine());
case 3:
// Handle pyramid drawing
Console.WriteLine("Enter the height of the pyramid:");
int pyramidHeight = int.Parse(Console.ReadLine());
case 4:
// Exit the loop
isContinueProgram = false;
27
break;
default:
// Handle invalid selections
Console.WriteLine("Invalid Selection. Please Try Again.");
continue; // Restart the loop if the selection is invalid
}
}
28