Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > C# 2012/5.0 General Discussion
|
C# 2012/5.0 General Discussion Discussions about the C# 2012 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2012/5.0 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2014, 03:33 PM
Authorized User
 
Join Date: Nov 2012
Posts: 25
Thanks: 3
Thanked 0 Times in 0 Posts
Question Need help fixing Constructor errors

My debugger is saying there are problems with my constructor but, I don't see any. I f someone could take a look at the could and help me get the program to the point were it will compile, I would appreciate it. I'm not worried about logical errors at this point. I just want the program to compile. I can't see any errors that would prevent this program from compiling. Please help. The code is below.

Thanks,
Truck35

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


   public class Fraction
    {
        //int numer = 0;
        //int denom = 0;
        //int wholeNum = 0;

        private int iDenomenator;
        private int iNumerator;
       // public int dInput;
        //public int nInput;
      //  private int iwholeNumber;
       // private int dOutput;
       // private int nOutput;

        public int IwholeNumber { get; set; }
        public int IDenomenator {
            set 
            {
                while (value == 0)
                {
                    if (value == 0)
                    {
                        Console.WriteLine("You have entered an invalid number");
                        Console.WriteLine("Please try again");
                    }
                    else
                    {
                        value = 1;
                        iDenomenator = value;
                    }
                }
            } 

            get
            {
                return iDenomenator;
            }
        
    }

        public int INumerator
        {
            set
            {  
                iNumerator = value;  
            }

            get
            {
                return iNumerator;
            }

        }

        public Fraction(int num, int whole, int den) 
        {

            INumerator = num;
            IwholeNumber = whole;
            IDenomenator = den;
            
   
            
        }

        public Fraction(int num, int den)
        {
             INumerator = num;
             IwholeNumber = 0;
             IDenomenator = den;
        }

        public Fraction(int whole)
        {
             //numer = 0;
             //denom = 1;
             //wholeNum = whole;

             INumerator = 0;
             IwholeNumber = whole;
             IDenomenator = 1;

        
        }
        public void Improper()
        {
            INumerator = IwholeNumber * IDenomenator;
            Console.Write(INumerator + "/" + IDenomenator);
        }

        public void SimpleReduce() 
        {
            INumerator = INumerator % IDenomenator;
            IwholeNumber = INumerator / IDenomenator;
            Console.Write(IwholeNumber + "   " + INumerator + "/" + IDenomenator);
        }

        public void Reduce() 
        {
            char[] iNumArray;
            char[] iDenomArray;
            //int divider = 2;
            int answer1 = INumerator;
            int answer2 = IDenomenator;

            iNumArray = Convert.ToString(INumerator).ToCharArray();
            iDenomArray = Convert.ToString(IDenomenator).ToCharArray();

            int nNum1 = Convert.ToInt32(iNumArray[0]);
            int nNum2 = Convert.ToInt32(iNumArray[1]);
            int dNum1 = Convert.ToInt32(iDenomArray[0]);
            int dNum2 = Convert.ToInt32(iDenomArray[1]);
            if (nNum2 % 2 == 0 && dNum2 % 2 == 0)
            {
                
                

                for (int i = 1; i < INumerator; ++i)
                {
                    if ((INumerator % 2 == 0) && (IDenomenator % 2 == 0))
                    {
                        answer1 = answer1 / 2;
                        answer2 = answer2 / 2;
                       

                    }
                }
            }
            Console.WriteLine("Reduced fraction is {0}/{1}", answer1, answer2);
        }
        
    }
    class DemoFraction : Fraction
    {
        static void Main(string[] args)
        {
            int numer = 0;
            int wholeNum = 0;
            int denom = 0;
            //string wholeNumString = null;

           /* Console.WriteLine("ZERO CAN NOT BE ENTERED FOR DENOMANATOR.");
            Console.WriteLine("Enter value for the whole number :");
            wholeNum = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter value for the denomanator: ");
            denom = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter value for the numerator: ");
            numer = Convert.ToInt32(Console.ReadLine());
            Console.Clear();*/
            

            Console.WriteLine("                 ********************************************");
            Console.WriteLine("                 * Choose Conversion type:                  *");
            Console.WriteLine("                 * ZERO CAN NOT BE ENTERED FOR DENOMANATOR. *");
            Console.WriteLine("                 *                                          *");
            Console.WriteLine("                 * \"M\"   Mixed Fraction to Improper       *");
            Console.WriteLine("                 *                                          *");
            Console.WriteLine("                 * \"I\"   Improper Fraction to Mixed       *");
            Console.WriteLine("                 *                                          *");
            Console.WriteLine("                 * \"R\"   Reduce Regular Fraction          *");
            Console.WriteLine("                 *                                          *");
            Console.WriteLine("                 ********************************************");

            char userChoice = Convert.ToChar((Console.ReadLine()));
            Console.Clear();
            
            if ((userChoice == 'M')||userChoice == 'm')
            {
                Console.WriteLine("Enter value for the whole number :");
                wholeNum = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter value for the denomanator: ");
                denom = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter value for the numerator: ");
                numer = Convert.ToInt32(Console.ReadLine());

                Fraction ob1 = new Fraction(denom, wholeNum, numer);
                ob1.Improper();
            }

            if ((userChoice == 'I') || userChoice == 'i')
            {
                
                Console.WriteLine("Enter value for the denomanator: ");
                denom = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter value for the numerator: ");
                numer = Convert.ToInt32(Console.ReadLine());

                Fraction ob1 = new Fraction(denom, numer);
                ob1.SimpleReduce();
            }

            if ((userChoice == 'R') || userChoice == 'r')
            {

                Console.WriteLine("Enter value for the denomanator: ");
                denom = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter value for the numerator: ");
                numer = Convert.ToInt32(Console.ReadLine());

                Fraction ob1 = new Fraction(denom, numer);
                ob1.Reduce();
            }
            
           
        }
    }
 
Old March 14th, 2014, 12:03 AM
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

Either remove the inhertance of Fraction on DemoFraction (preferred as the DemoFraction does not need to inherit Fraction for it to use it) or define a 0 argument constructor on Fraction

Last edited by mmorgan30; March 14th, 2014 at 08:18 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixing An Overbloated MDB - HELP!! dpm39560 Access 4 October 14th, 2014 05:59 AM
Image fixing majeedkhan BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 February 18th, 2010 02:12 AM
Urgent...need help fixing this error! riki_gill ASP.NET 1.x and 2.0 Application Design 0 October 27th, 2006 08:23 AM
HELP! FIXING MY QUERY dstein4d Access 2 January 21st, 2006 03:24 AM
errors and fixing errors Droopy XML 0 August 26th, 2003 12:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.