Thursday, 25 April 2013

David needs to create a program to maintain the details of the stock of a shop. He needs to ensure that item category is Women, Men, Girls, Boys, and Babies. He needs to accept item category from the user. In addition, he needs to accept item name, number of units, and unit price. Finally, he needs to display all the details.


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

namespace ConsoleApplication27
{
    class shop
    {
        string item;
        int up, total, unit;
        public void accept()
        {
            Console.WriteLine("Enter the item name:");
            item = Convert.ToString(Console.ReadLine());
            Console.WriteLine("Enter units of item:");
            unit = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter the unnit price:");
            up = Convert.ToInt32(Console.ReadLine());

        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string cat;
            shop s = new shop();
            Console.WriteLine("Enter the catagory:");
            cat = Convert.ToString(Console.ReadLine());
            switch (cat)
            {
                case "women":
                    s.accept();
                    break;
                case "men":
                    s.accept();
                    break;
                case "girls":
                    s.accept();
                    break;
                case "boys":
                    s.accept();
                    break;
                case "babies":
                    s.accept();
                    break;
                default:
                    Console.WriteLine("Invalid Selection");
                    break;
            }
            Console.ReadLine();
        }
    }
}

Wednesday, 24 April 2013

Predict the output of the following program:


using System;
namespace CalculateNumber
{
class Calculate
{
static int number1;
public void Display(int number)
{
Console.WriteLine(number);
}
Calculate()
{
number1++;
Display(number1);
}
static Calculate()
{
number1 = 10;
number1++;
}
static void Main(string[] args)
{
Calculate Cal1 = new Calculate();
Calculate Cal2 = new Calculate();
Console.ReadLine();
}
}
}
(Duration: 15 min)

Predict the output of the following program:


Predict the output of the following program:
using System;
namespace Square_Number
{
class CalculateSquare
{
int number;
public void Square(int number)
{
Console.WriteLine("The number is: {0}",number);
number *= number;
Console.WriteLine("Square of 10 is: {0}", number);
}
CalculateSquare()
{
number = 10;
Square(number);
}
static void Main(string[] args)
{
CalculateSquare cal = new CalculateSquare();
Console.ReadLine();
}
}
}
(Duration: 15 min)

Write a program to identify the largest of three numbers entered by a user. Create this program by using methods. (Duration: 25 min)


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

namespace ConsoleApplication72
{
   public class Program
    {
       static int number1, number2, number3;
       public static void Greater()
       {
           if (number1 > number2 && number1 > number3)
           {
               Console.WriteLine("first number is the greatest:{0}", number2);
           }
           else if (number2 > number1 && number2 > number3)
           {
               Console.WriteLine("second number is the greatest:{0}", number2);
           }
           else
           {
               Console.WriteLine("this number is the greatest:{0}", number3);
           }
       }
        static void Main(string[] args)
        {
            Console.WriteLine("enter the first number");
            number1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("enter the second number");
            number2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("enter the third number");
            number3 = Convert.ToInt32(Console.ReadLine());
            Console.ReadLine();
        }
    }
}

Write a program to identify the largest of three numbers entered by a user. Create this program by using methods. (Duration: 25 min)


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

namespace ConsoleApplication72
{
   public class Program
    {
       static int number1, number2, number3;
       public static void Greater()
       {
           if (number1 > number2 && number1 > number3)
           {
               Console.WriteLine("first number is the greatest:{0}", number2);
           }
           else if (number2 > number1 && number2 > number3)
           {
               Console.WriteLine("second number is the greatest:{0}", number2);
           }
           else
           {
               Console.WriteLine("this number is the greatest:{0}", number3);
           }
       }
        static void Main(string[] args)
        {
            Console.WriteLine("enter the first number");
            number1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("enter the second number");
            number2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("enter the third number");
            number3 = Convert.ToInt32(Console.ReadLine());
            Console.ReadLine();
        }
    }
}

Write a program to calculate the factorial of the number entered by a user. Create this program by using static functions and static variables. Hint: The limit of users input should be 1-20. (Duration: 30 min)


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

namespace ConsoleApplication71
{
    class factorial
    {
        static long Facl;
        public static bool Fac(long n, out long answer)
        {
            long k;
            bool ok = true;
            if (n <= 0 || n > 20)
            {
                ok = false;
            }
            else
            {
                Facl = 1;
                for (k = 2; k <= n; ++k)
                {
                    Facl = Facl * k;
                }
                answer = Facl;
                return ok;
            }
        }
        static void Main(string[] args)
        {
            long facl;
            bool ok;
            long number;
            Console.WriteLine("enter the number for calculating factorial(1-20):");
            number = long.Parse(Console.ReadLine());
            ok = factorial.Fac(number, out facl);
            if (ok)
                Console.WriteLine("factorial(" + number + ")=" + facl);
            else
                Console.WriteLine("incorrect value");
            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();
        }
    }
}

• • • • 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 Rohit{


    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();
}
}
}

   

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 to enter a number from 1 to 7 and display the corresponding day of the week. Hint: 1 = Monday (Duration: 30 min)


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

namespace number_from_1_to_7
{
    class Day
    {
        static void Main(string[] args)
        {
            int num;
            Console.WriteLine("Entre a number");
            num = Convert.ToInt32(Console.ReadLine());
            switch (num)
            {
            case 1:
            Console.WriteLine("Monday");
            break;
                case 2:
            Console.WriteLine("Tuesday");
            break;
                case 3:
            Console.WriteLine("Wednesday");
            break;
                case 4:
            Console.WriteLine("Thursday");
            break;
                case 5:
            Console.WriteLine("friday");
            break;
                case 6:
            Console.WriteLine("Saturday");
            break;
                case 7:
            Console.WriteLine("Sunday");
            break;
                default:
            Console.WriteLine("Invalid Number");
            break;
            }
        }
    }
}

Write a program to print the product of the first 10 even numbers. (Duration: 30 min)


using System;
using System.Collections.Generic;
using System.Text;
 namespace Divisible
{
class product_Even
{
static void Main(string[] args)
{
int nNum, nEven;
double nProd;
nNum=2; nEven=0; nProd=1;
while(nEven<10)
{
    nProd = nNum*nProd;
    nNum=nNum+2;
    nEven = nEven + 1;
    Console.WriteLine("The product of first 10 even numbers is:{0}",nProd);
    }
}
}
}

Write a program to display the highest of any 10 numbers entered. (Duration: 30 min)


using System;
using System.Collections.Generic;
using System.Text;
namespace largest_loop
{
class program
{
static void Main(string[]args)
{
int ctr, nNum1, max=0;

for (ctr=0; ctr<=9; ctr++)
{
    Console.WriteLine("Enter the numbers"+(chr+1));
nNum1 = Console.ToInt32(Console.ReadLine());
if (nNum1>max)
     max=nNum1;

}
Console.WriteLine(max);
    Console.ReadLine();
}
}
}

Write a program to accept two numbers and display the quotient as a result. In addition, an error message should be displayed if the second number is zero or greater than the first number. (Duration: 20 min)


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

namespace two_number_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1, num2, result;
            Console.WriteLine("Enter two numbers");
            num1 = Convert.ToInt32(Console.ReadLine());
            num2 = Convert.ToInt32(Console.ReadLine());
            if (num2 != 0)
            {
                if (num2 < num1)
                {
                    result = num2 / num2;
                    Console.WriteLine("result");
                }
                else
                {
                    Console.WriteLine("A number cannot be divided by a number greater than itself");
                }
            }
            else
            {
                Console.WriteLine("A number cannot be divided by zero");
            }
        }

    }
}

Write a program to accept two numbers and check if the first is divisible by the second. In addition, an error message should be displayed if the second number is zero. (Duration: 40 min)


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1, num2, result;
            Console.WriteLine("Enter First Number");
            num1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter socond Number");
            num2 = Convert.ToInt32(Console.ReadLine());
            if (num2 == 0)
            {
                Console.WriteLine("You cannot divide by 0");
            }
            else
            {
                result = num1 % num2;
                if (result ==0)
                    Console.WriteLine("Divisidle");
                else

                Console.WriteLine("Not DIvisible");
            }

        }
    }

}

Write a program to accept a number from the user and display all the prime numbers from one up to the number entered by user. (Duration: 40 min)


using System;
class primeNumber
{
public void PrimeNum(int Num)
{
Boolean isPrime=true;
Console.WriteLine("\nThe prime numbers between 1-{0} is:",Num);
for (int i = 0; i <=Num; i++)
{
for (int j = 2; j<=Num; j++)
{
if (i !=j && i == 0)
{
isPrime = false;
break;
}
}
if (isPrime == true)
{Console.WriteLine("{0}",i);}
isPrime = true;
}
}
}
class EntryPoint
{
static void Main (string[]args)
{
int Num;
PrimeNumber FindPrimeNo = new PrimeNumber();
string str;
Console.WriteLine("Enter the number till which you want to show the prime Numbers");
str = Convert.ReadLint();
Num = Convert.PrimeNum(Num);
Console.ReadLint();
}
}

Write a program to identify whether the number entered by a user is even or odd. (Duration: 40 min)


using System;
class EvenOddNumber
{
static void Main (string [] args)
{
int Number;
Console.WriteLine("Enter the number to be checked as Even or Odd");
Number = Convert.ToInt32(Console.ReadLine());
if (Number % 2 == 0)
{
Console.WriteLine(" The number you have entered is an Even number");
}
else
{
Console.WriteLine("The number you need entered is an Odd number");
}
Console.ReadLine();
}
}

David is a cricket coach of a local team. He is analyzing the performance of one of his batsman. For this, he wants a program that should accept the number of recent matches for which the scores of the batsman need to be analyzed. After this, the program should accept the scores of the batsman for these matches, and then display the scores in ascending order. Help David create the program. Hint: Declare an integer array with a maximum capacity of 100 elements. (Duration: 40 min)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Sorting of a Number
namespace chapter4
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[100];
            Console.Write("Enter the number of recent matches for which the scores of the batsman need to be analyzed:");
            string s = Console.ReadLine();
            int x = Int32.Parse(s);

            Console.WriteLine("======================");
            Console.WriteLine("Enter the scores:");
            Console.WriteLine("======================");
            for (int j = 0; j < x; j++)
            {
                string s1 = Console.ReadLine();
                a[j] = Int32.Parse(s1);
            }
            int limit = x - 1;
            for (int pass = 0; pass < x - 1; pass++)
            {
                for (int j = 0; j < limit -pass; j++)
                {
                    if (a[j] > a[j + 1])
                    {
                        int k = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = k;

                    }
                }
            }
            Console.WriteLine("========================================================");
            Console.WriteLine("Scorted scores of the batsman are:");
            for (int j = 0; j < x; j++)
                Console.WriteLine(a[j]);
            Console.ReadLine();
        }
    }
}

Write a C# program that accepts distance in kilometers, converts it into meters, and then displays the result. (Duration: 45 min)


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

namespace Quotient
{
    class Meter_Kilometer
    {
        static void Main(string[] args)
        {
            int nDistance, nResult;
            Console.WriteLine("Enter the distance in kilometers");
            nDistance = Convert.ToInt32(Console.ReadLine());
            nResult = nDistance * 1000;
            Console.WriteLine("Distance in meters:" + nResult);
            Console.ReadLine();
        }
    }
}

Write a program to identify whether a character entered by a user is a vowel or a consonant. (Duration: 30 min)


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

namespace character
{
    class VowelConsotant
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the Alphabet");
            Alphabet = Convert.ToChar(Console.ReadLine());
                       switch (Alphabet)
            {
                case 'a':
                case 'e':
                case 'i':
                case 'o':
                case 'u':
            }
        }
    }
}

Write a program that displays "Congratulations! You have cleared this Level. Entering Level 2..." in red color. The output of this program is shown in the following figure. (Duration: 30 min)


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

namespace Congratulations
{
    class Game
    {
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("\n\n\n\n\n\n");
            Console.WriteLine("\t\tCongratulations");
            Console.WriteLine("\n\n");
            Console.WriteLine("\t\t\t\tEntering! You have cleared this Level");
            Console.ReadLine();
        }
    }
}