Likes

C# LAB at HoM 7

Enter a year and determine whether the year is a leap year or not. A leap year is a noncentury year that is divisible by 4. A century year is a year divisible by 100, such as 1900. A century year, which is divisible by 400, such as 2000, is also a leap year. Hint: If a year is divisible by 4 and is not divisible by 100 or divisible by 400, it is a leap year. (Duration: 30 min)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Leap
{
    class Program
    {
        public static void Main(string[] args)
        {
            int nYear;
            Console.WriteLine("Please enter the year");
            nYear = Convert.ToInt32(Console.ReadLine());
            if (nYear % 400 == 0 || (nYear % 100 != 0 && nYear % 4 == 0))
            {
                Console.WriteLine("This is a leap year");
            }
            else
            {
                Console.WriteLine("This is not a leap year");
            }
        }
    }
}





• • • • Write a program that should accept two numbers from the users and perform the following mathematical operations: Addition Subtraction Multiplication Division In case of division, an error message should be displayed if the second number is zero. (Duration: 35 min)

using System;

namespace Kamal{


    class Program{


static int res;
public static void addition(int a ,int b)
{
res = a+b;
Console.WriteLine("The sum of the two number entered is {0}",res);
}
public static void subtraction(int a ,int b)
{
res = a -b;
Console.WriteLine("The difference of the numbers entered is {0}",res);
}

public static void Multiplication(int a, int b)
{
res = a *b;
Console.WriteLine("The product of the two numbers entered is {0}",res);
}
public static void division(int a, int b)
{
if(b==0)
{
Console.WriteLine("You cannot divide by 0");
}
else
{
res = a / b;
Console.WriteLine("The division of the two numbers entered gives {0}",res);
}
}
static void Main(string[] args)
{
int Num1, Num2, ch;
string str1, str2, str3;
Console.WriteLine("Enter the first number:");
str1 = Console.ReadLine();
Num1 = Convert.ToInt32(str1);

Console.WriteLine("Enter the second number:");
str2 = Console.ReadLine();
Num2 = Convert.ToInt32(str2);

Console.WriteLine("Menu");
Console.WriteLine("1.Addition");
Console.WriteLine("2.Subtraction");
Console.WriteLine("3.Multiplication");
Console.WriteLine("4.Division");
Console.WriteLine("Enter the Operation you want to perform");
str3 = Console.ReadLine();
ch = Convert.ToInt32(str3);
switch (ch)
{
case 1:
addition(Num1, Num2);
break;
case 2:
subtraction (Num1, Num2);
break;
case 3:
Multiplication (Num1, Num2);
break;
case 4:
division (Num1, Num2);
break;
}
Console.ReadLine();
}
}
}





1. 2. 3. 4. Write a program that displays a menu as shown in the following figure. The program should implement the following features: If the user enters the option 1, the program should display "This application will allow you to create a pattern in pyramid structure.". If the user enters option 2, then the program should display "This application will allow you to add two primary colors and displays the third color.". If the user enters option 3, the program should display "This application will allow you to create a meaningful word from jumbled letters.". If the user enters option 4, the program should display "This application will allow you to create multiple words from a single word. Each correct word will increase your score by 1.". (Duration: 30 min)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MenuApplication
{
    class menu
    {
        int no;
        public void displayMenu()
        {
            Console.WriteLine("\n\n\n");
            Console.WriteLine("\t\t***************APPLICATION MENU**********************");
            Console.WriteLine("\n");
            Console.WriteLine("\t\t\t1.CREATE PATTERNS\n\t\t\t4.PUZZLE COLORS\n\t\t\t3.JUMBLED WORDS\n\t\t\t4. PUZZLE");
            Console.WriteLine("\n************************************************");
        }
        public void AcceptData()
        {
            Console.WriteLine("\n\t\tPlease enter the application number for the details:");
            no = Convert.ToInt32(Console.ReadLine());
            switch (no)
            {

                case 1: Console.WriteLine("This application will allow you to create a primary in pyramid structure.");
                    break;
                case 2: Console.WriteLine("This application will allow you to add two primary colors and display the third color.");
                    break;
                case 3: Console.WriteLine("This application will allow you to create a meaningful word from jumbled letters.");
                    break;
                case 4: Console.WriteLine("This application will allow you to create multiple words from a single word.\nEach correct word will increase your score by 1.");
                    break;
                default: Console.WriteLine("Not a valid menu number");
                    break;
            }
        }
        static void Main(string[] args)
        {
            menu menu = new menu();
            menu.displayMenu();
            menu.AcceptData();
        }
    }
}

No comments: