redlotus
Replies to this thread:

More by redlotus
What people are reading
Subscribers
Subscribers
[Total Subscribers 1]

Rolemodel
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 C # help(new to c#)
[VIEWED 7899 TIMES]
SAVE! for ease of future access.
Posted on 03-14-09 8:30 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Here's what i did and its not giving me right answer, question is below: this is my first class so having hard time. pls help

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

namespace assignement1_nepal
{

    class PhoneCall
    {
        public:
        double min;
        double totalcost;
        const double unitcost = 0.10;
        
        void NumberOfMin()
        {
            Console.WriteLine(" Enter min:");
            min = Convert.ToDouble(Console.ReadLine());
        }

        Double CalculateCost(double min)
        {
            totalcost = min * unitcost;
            return totalcost;
        }

        void Output()
        {
            Console.WriteLine(" total cost:{0}", totalcost);
        }

    }
    class threecalls
    {
        static void Main(String[] args)
    {
        
        PhoneCall callone = new PhoneCall();
        for(int i=0; i<3;i++)
        {
        callone.NumberOfMin();
        callone.Calculatecost();
        callone.Output();


        }
    }
    }

}

question:

You may look up similar programs on the web or in
your books, but be sure you use your code for this project. Commenting
blocks of code in the real world is usually sufficient. Document enough
to show that you understand what is going on.

  1. PhoneCall class with a public data member that contains the number of minutes in a phone call.
  2. Public class method to get the number of minutes.
  3. Public class method to calculate the cost based on 10 cents per minute
  4. Public class method to output the total cost of the phone call.
  5. Main( ) function that instantiates one PhoneCall object, and includes a for loop to calculate the cost of three
    phone calls. The next chapter covers looping, however, you should be
    able to build a for-loop to accomplish the three phone calls. A
    for-loop in C# is no different than a for-loop in C++ or Java.
  6. Internal Documentation

Here is an example of a class definition:

namespace ConsoleApplication1
{
/*
Introduction to Classes
*/

class Product
{
public:
int productIdNum;
string productName;
double productPrice;

 
    /*

  Note:

  • class is a keyword

  • Product is a name you make up - it should be descriptive

  • A class contains data (data members) and functions (methods)

  • You cannot initialize your data members in the class definition

  • You end the class definition with a semicolon

  Here is an example of the class methods implemented inside of the class structure:

    */

void displayProduct()
{
Console.WriteLine("Product ID Number: {0}", productIdNum);
Console.WriteLine("Product Name: {0}", productName);
Console.WriteLine("Product Price: ${0}", productPrice);
}


void getProductData() //this method gets the data and stores it in the class data members
{
Console.Writeline("Enter the Product name: ");
productName = Console.Readline();
Console.Writeline("Enter the price of the product: ");
productPrice = Convert.ToDouble(Console.Readline());
}

    }	//end of class Product						 

/*
      The C# class Product above is placed outside of the class Program below which is created with the project 
      as an object wrapper for the Main function.

Note:

  • the void is the return type for both methods(in this case we are not returning anything)

  • Console.WriteLine is used to write the string literal and variable value with a newline at the end of the write

  • Console Readline is used to assign the input of the product price into the productPrice variable

  • The product price read from the console is string and must be converted to double before assigning it to the double variable productPrice

Here is an example of how to instantiate an object and call a method:

    */

class Program
{
static void Main(string[] args)
{

Product oneProduct = new Product(); //instantiation of the Book class
oneProduct.getProductData(); //method call
oneProduct.displayProduct(); //method call

}

} //end of function main
} //end of namespace ConsoleApplication1




 
Posted on 03-14-09 8:50 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Suruma herdai ma dekheko mistake
Call garda yasto chha   callone.Calculatecost();No argument passed here.

mathi defined gareko function ma Argument lirako chha.Fix this.


Double CalculateCost(double min) 
        {
            totalcost = min * unitcost;
            return totalcost;
        }


for example tyo method lai yasari declare gara.sabai method lai public declare gara.Normally methods should be public and attribute as private.

public Double CalculateCost()
        {
            totalcost = min * unitcost;
            return totalcost;
        }



Tespachhi thik hunchha.





 
Posted on 03-14-09 8:53 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Looks like you are not a beginner in C# only, you are new to programming as well...

Here is the final code:

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

namespace assignement1_nepal
{

    public class PhoneCall
    {
        public double min;
        double totalcost;
        const double unitcost = 0.10;
        
        public void NumberOfMin()
        {
            Console.WriteLine(" Enter min:");
            min = Convert.ToDouble(Console.ReadLine());
        }

        public double CalculateCost()
        {
            totalcost = min * unitcost;
            return totalcost;
        }

        public void Output()
        {
            Console.WriteLine(" total cost:{0}", totalcost);
        }

    }
    class threecalls
    {
        static void Main(String[] args)
    {
        
        PhoneCall callone = new PhoneCall();
        for(int i=0; i<3;i++)
        {
        callone.NumberOfMin();
        callone.Calculatecost();
        callone.Output();


        }
    }
    }

}

This should work. Cheers :)


 
Posted on 03-15-09 8:29 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Bro purai question copy paste hannu bhanda ta afule garne try gare huncha ni. Yo question university ko professor le dekhyo bhane ke huncha? Ki ma send gardeu? Afule le garne gara na.....pachi interview ma ke bolchau....kaam ma ke garchau.....grade ramro ayera kehi hudaina,,,,main kura jannu ho..kaam ma, interview ma grade herdaina...materials aucha ko audaina bhanera hercha....



I ask all the guys not to solve the problem.........

 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 60 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
Toilet paper or water?
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
Tourist Visa - Seeking Suggestions and Guidance
From Trump “I will revoke TPS, and deport them back to their country.”
advanced parole
ढ्याउ गर्दा दसैँको खसी गनाउच
To Sajha admin
MAGA denaturalization proposal!!
How to Retrieve a Copy of Domestic Violence Complaint???
wanna be ruled by stupid or an Idiot ?
Travel Document for TPS (approved)
All the Qatar ailines from Nepal canceled to USA
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters