I'm not sure what I am doing wrong, but I am trying to create a new object and it gives me the error that it does not contain a constructor with 0 arguments. I understand that the way I am writing it causes it to appear like it's parameterless, but I do not know how to fix it. The ultimate goal is to create a series of orders that will display to the screen with the details. I only have one order information set up, Ben Franklin's order, but intend on having more. Here is my code: -
public class Order
-
{
-
private int orderNum;
-
private string custName;
-
private int quantOrdered;
-
private int totalPrice;
-
private double price = 19.95;
-
-
public Order(int ordNum, string name, int quantity)
-
{
-
OrderNum = ordNum;
-
CustName = name;
-
QuantOrdered = quantity;
-
}
-
public override string ToString()
-
{
-
return ("Order Number: " + OrderNum + "Customer Name: " + CustName + "Quantity Ordered: " + QuantOrdered + "Total Price: " + TotalPrice.ToString("C"));
-
}
-
-
-
public int OrderNum{get; set;}
-
public string CustName { get; set; }
-
public int QuantOrdered
-
{
-
get
-
{
-
return quantOrdered;
-
}
-
set
-
{
-
quantOrdered = value;
-
totalPrice = Convert.ToInt32(quantOrdered) * Convert.ToInt32 (price);
-
}
-
}
-
public int TotalPrice
-
{
-
get
-
{
-
return totalPrice;
-
}
-
}
-
-
public static void Main()
-
{
-
-
Order aOrder = new Order();
-
aOrder.OrderNum = 1;
-
aOrder.CustName = "Franklin, Benjamin";
-
aOrder.QuantOrdered = 6;
-
Console.WriteLine("Order information: {0}", aOrder);
-
}
-
-
-
}
-
}
-
The error message states: Error 1 'OrderDemo.Orde r' does not contain a constructor that takes '0' arguments
1 1507
I figured it out. I declared the parameters like this: -
public static void Main()
-
{
-
-
Order aOrder = new Order(1, "Franklin, Benjamin", 6);
-
Order aOrder2 = new Order(2, "Jefferson, Thomas", 4);
-
Console.WriteLine("Order information:\n {0}\n{1}", aOrder, aOrder2);
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: hellwolf |
last post by:
Hi,everyone.Because of my English level,I will try to use code to explain
where I confused.
//list of code:
#include <iostream>
#include <algorithm>
#include <vector>
class A{
static int si;
|
by: indushekara |
last post by:
Hi,
I want to know what is the problem with this code. I am trying to insert in
a map<int,A> where in i have defined the copy constructor for A
I get the following error in VS6.
e:\program files\microsoft visual studio\vc98\include\utility(21) : error
C2558: class 'A' : no copy constructor available
e:\program files\microsoft visual studio\vc98\include\utility(21) :
while compiling class-template member function '__thiscall std::pair<int...
|
by: John Haigh |
last post by:
Should possibly have an "add" method in a PostingObject class in the
constructor of PostingObject. will call to add a Posting to the ? Does this
make sense? My sense is that a PostingObject needs a Posting, so would I do
this in the PostingObject Constructor?
Here is my code:
using System;
using System.Collections;
using Microsoft.ContentManagement.Publishing;
|
by: Daniel Groh |
last post by:
Im my Application_Error i have a code that throw an error to my Email when
any errors occurs, but the application is running normally and sometimes i
get the following error in my Email address:
Error Caught in Application_Error event
Error in: http://localhost/LivrosOnline/get_aspx_ver.aspx
Error Message:C:\Inetpub\wwwroot\LivrosOnline\get_aspx_ver.aspx
Stack Trace: at System.Web.UI.TemplateParser.GetParserCacheItem()
at...
|
by: Joe Fallon |
last post by:
I have a Shared class with a New constructor that initializes some Shared
properties.
One of the steps involves a hit to the database.
My tests show that when called by a WinForms app, the constructor only runs
once.
All calls to the class after this do not casues the construtor to run again.
This means it is a one time hit to the database to load these properties.
1. Can someone confirm this?
| |
by: Indian.croesus |
last post by:
Hi,
If I am right Endianness is CPU related. I do not know if the
question is right in itself but if it is then how does C handle issues
arising out of Endianness.
I understand that if we pass structures using sockets across platforms,
we need to take care of Endianness issues at the application level. But
for example, for the code using bitwise AND to figure out if a number
is odd or even, how does C know the LSB position?
|
by: emadazizsuria |
last post by:
I'm getting the following error:
'Questionnaire' does not contain a definition for 'ProcessList'
Here Questionnaire.cs is a class file that defines a getter function ProcessList.
public class Questionnaire
{
private ArrayList ImpProcesses;
public Questionnaire()
{
|
by: JosephLee |
last post by:
In Inside C++ object Model, Lippman said there are four cases in which
compile will sythesize a default constructor to initialize the member
variables if the constructor is absent:
1. there is a virtual function;
2. virtual inheritance;
3.base class with explicit default constructor;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |