Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[C#] Classes example
04-05-2010, 02:42 PM
Post: #1
[C#] Classes example
Code:
/*
* Created by SharpDevelop.
* User: Back_Track
* Date: 4/4/2010
* Time: 11:29 PM
*/
using System;

namespace class_
{
    class Program
    {
        public static void Main(string[] args)
        {
            int choice;//Just for the 1,2 choice
            Programming Pascal = new Programming();//Create a variable with the values of the Programmig Class
            Pascal.Scripted = false;//Set the variables from the class
            Pascal.IsOO = false;
            Pascal.Year_Made = 1968; //1968/9 Published 1970
            Pascal.Operating_Systems = "Windows/Mac/Linux";
            
            Programming Cxx = new Programming();//C++
            Cxx.Scripted = false;
            Cxx.IsOO = true;
            Cxx.Year_Made = 1983;
            Cxx.Operating_Systems = "Windows/Mac/Linux";
            
            Console.WriteLine("Lets test your programming knowledge!\nWhich Language would you like to be tested on.\n1)Pascal\n2)C++");
            Int32.TryParse(Console.ReadLine(),out choice);
            
            string Script,IsOO,OS;//For checking
            int Year,right=0;
            if(choice == 1)
            {
                Console.WriteLine("Is Pascal a scripted language? (Answers, yes or no)");
                Script = Console.ReadLine();//Get input
                Console.WriteLine("Is Pascal Objected Oriented? (Answers, yes or no)");
                IsOO = Console.ReadLine();
                Console.WriteLine("What year was pascal invented? (Answers, Numeric)");
                Int32.TryParse(Console.ReadLine(), out Year);
                Console.WriteLine("What Operating Systems is Pascal available on (Answers, Windows/Mac/Linux)");
                OS = Console.ReadLine();
                
                if(Script == "no")
                {
                    right++;//If you got it right increment the 'correct' int
                }
                if(IsOO == "no")
                {
                    right++;
                }
                if(Year == Pascal.Year_Made )
                {
                    right++;
                }
                if( OS == Pascal.Operating_Systems)
                {
                right++;
                }
                Console.WriteLine("You got {0}/4 right",right);
                
            }
            
            
            
            
            if(choice == 2)
            {
                Console.WriteLine("Is C++ a scripted language? (Answers, yes or no)");
                Script = Console.ReadLine();
                Console.WriteLine("Is C++ Objected Oriented? (Answers, yes or no)");
                IsOO = Console.ReadLine();
                Console.WriteLine("What year was C++ invented? (Answers, Numeric)");
                Int32.TryParse(Console.ReadLine(), out Year);
                Console.WriteLine("What Operating Systems is C++ available on (Answers, Windows/Mac/Linux)");
                OS = Console.ReadLine();
                
                if(Script == "no")
                {
                    right++;
                }
                if(IsOO == "yes")
                {
                    right++;
                }
                if(Year == Cxx.Year_Made )
                {
                    right++;
                }
                if( OS == Cxx.Operating_Systems)
                {
                right++;
                }
                Console.WriteLine("You got {0}/4 right",right);
            }
            
            else{
                
            }
            
            
            
            Console.ReadLine();
            
    }
    
    class Programming//Create a class of Programmign
    {
        public bool Scripted;
        public bool IsOO;//Self Explanatory
        public int Year_Made;
        public string Operating_Systems;
        
        
    }
    }
}
Simple Class example , with explanation.

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
04-05-2010, 09:06 PM
Post: #2
RE: [C#] Classes example
Very good class example. Declaring classes in C# is fun.
I like the way that you used "?" operator in input.

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: