[VIEWED 7961
TIMES]
|
SAVE! for ease of future access.
|
|
|
redlotus
Please log in to subscribe to redlotus's postings.
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. - PhoneCall class with a public data member that contains the number of minutes in a phone call.
- Public class method to get the number of minutes.
- Public class method to calculate the cost based on 10 cents per minute
- Public class method to output the total cost of the phone call.
- 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. - 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
|
|
|
|
iluvnepal
Please log in to subscribe to iluvnepal's postings.
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.
|
|
|
krishnaram
Please log in to subscribe to krishnaram's postings.
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 :)
|
|
|
rajmani
Please log in to subscribe to rajmani's postings.
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.........
|
|