Why won\'t this C++ program run? Code Below: //OfficeSupply.h #ifndef GOLDFISH_H
ID: 3732402 • Letter: W
Question
Why won't this C++ program run?
Code Below:
//OfficeSupply.h
#ifndef GOLDFISH_H
#define GOLDFISH_H
#include <iostream>
#include <iomanip>
using namespace std;
class Goldfish
{
public:
Goldfish();
Goldfish ( int, char [], double );
int GetInventoryNumber() const;
char* GetGoldfishType () const;
double GetPrice () const;
void Display() const;
private:
int InventoryNumber;
double Price;
mutable char GoldfishType[25];
};
#endif
//Mainform.H
#pragma once
namespace Program2Sample {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Runtime::InteropServices;
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e)
{
PictureBox->Image=
Image::FromFile(String::Concat(Directory::GetCurrentDirectory(),"\Splash.jpg"));
}
private: System::Void ExiButton_Click(System::Object^ sender,
System::EventArgs^ e)
{
Application::Exit();
}
private: System::Void NumberInputBox_Click(System::Object^ sender,
System::EventArgs^ e)
{
NumberInputbox->Clear();
TypeInputbox->Clear();
PriceInputbox->Clear();
NumberOutputbox->Clear();
TypeOutputBox->Clear();
PricOutputbox->Clear();
}
private: System::Void DisplayButton_Click(System::Object^ sender, System::EventArgs^ e)
{
int InitInventoryNumber = 0;
char* InitType;
double InitePrice = 0.0;
String^ TypeString;
InitInventoryNumber = Concert::ToInt32(NumberInputBox->Text);
InitType = (char*) (void*)Marshal::StringToHGlobalAnsi(TypeInputBox->Text);
Goldfish InventoryItem(InitInventoryNumber, InitType, InitPrice);
NumberOutputBox->Text = Convert:;ToString(InventoryItem.GetinventoryNumber());
Type String = gcnew String (InventoryItem.GetInventoryNumber());
TypeOutputBox->Text = TypeString;
PriceOutputBox->Text = ( (Decimal) (InventoryItem.GetPrice()) ).ToString("c");
}
}
//Supply.cpp
#include "stdafx.h"
#include "OfficeSupply.h"
Goldfish::Goldfish()
{
InventoryNumber = 0;
GoldfishType[24] = '';
Price = 0;
}
Goldfish::Goldfish (int InitInventoryNumber, char InitGoldfishType[], double InitPrice )
{
InitInventoryNumber = InitInventoryNumber;
strcpy_s( GoldfishType, InitGoldfishType );
Price = InitPrice;
int Goldfish::GetInventoryNumber() const
{
return (InventoryNumber);
}
char* Goldfish::GetGoldfishType() const
{
return (GoldfishType);
}
double Goldfish::GetPrice() const
{
return (Price);
}
void Goldfish::Display() const
{
char Separator[50] = "_________________________________________________";
cout << endl; << Separator << endl << endl;
cout << setw(36) << setfilll (' ') << "Goldfish Supply Company" << endl;
cout << Separator;
cout << endl; << endl << setw(15) << setfill (' ') << "Identification"
<< setw(12) << setfill{' ') << "Type Of"
<< setw(17) << setfill{' ') << "Price" << endl
<< setw(11) << setfill{' ') << "Number"
<< setw(17) << setfill{' ') << "Goldfish"
cout << endl << Separator << endl << Separator << endl;
cout << right;
cout << endl << setw(9) << setfill(' ') < GetInventoryNumber();
cout << setw(18) << setfill(' ') << GetGoldfishType();
cout << fixed << showpoint << setprecision(2)
setw(12) << setfill (' ')
<< " $ " << GetPrice()
<< endl;
<< cout << Separator << endl;
}
//OfficeSupply.cpp
// OfficeSupply.cpp : main project file.
#include "stdafx.h"
#include "MainForm.h"
using namespace Program2Sample;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
//stdafx.cpp
#pragma once
#include "stdafx.h"
#include "OfficeSupply.h"
Attached Errors:
·* 59 Errors | ! 0 warnings 00 Messages Seardh Error List Column Project 1 error C2059: syntax error: private 32 eror C2143: syntax error: missing before'- 3 error C2059: syntax error: private 34 error C2059: syntax error: private 35 error C2055:NumberInputbox': undeclared identifier 36 error C2227: left of Clear must point to dass/struct/urion/generic type 29 7 error C2065: Typelnputbox': undeclared identifier 38 error C2227: left of Clear must point to dass/struct/urion/generic type 39 error C2055: PriceInputbox' : undedared identifer 10 error C2227: left of Clear must point to dlass/jstructjunionýgeneric type 11 error C2065:NumberOutputbox': undedared identfier 12 error C2227: left of Clear must point to dlassjstruct/unionýgeneric type 13 error C2065: TypeOutputBox: undedared identfier 14 error C2227: left of Clear must point to dass/structjunionýgeneric type 15 eror C2065: Pricoutputbox: undedared identfier 16er C2227: left of" >Clear must point to dass structjunion/generic type * 17 error C2059: syntax error : private' 35 18 err C2653 Concert: is not a dass or namespace name 319 error C2065: umberInputsox : undeclared identfier 20 error C2227: left of >Text must point to 321 error C3361: Tont32: identfier not found 322 error C2055:TypeinputBox': undedared identfer 23 error C2227: left of >Text must point to dass/struct/union/generic type 324 errer C2055: Goldfish': undeclared idenbfer 25 error C2146: syntax error missing before identifier Inwentoryltem 26 error C2055: InitPrice': undedared identifier 327 error C3361: InventoryItem: idenifer not found 328 error C2055:NumberOutputBox' : undedered identfier 329 error C2227: left of ->Text must point to dass/struct/union/generic type 3 30 error C2143: syntax error : missing before 31 error C2065: Inventoryltem': undecared identifier 32 error C2228: left of .GetinventoryNumber must have class struct/union 33 eror C3361: ToString: idenbfier not found * 34 error C3522: Systeme :Type: a dass declared aG 'abstract' cannot be nstantated 35 error C2051: syntax error: identfier String 36 error C3767: System::Type::Type: canddate function(s) not accessible 337 error C2055: TypeOutputBox: undedared identifier 38 eror C2227: left of->Text must point to dass/struct/union/generic type 39 error C2055: PriceOutputBox: undedared identifer 40 error C2227: left of >Text must point to dass/struct/union/generic type 52 52 41 error C2055: Inventoryltem: undedared identifier 342 error C2228 left of ".GetPrice must have dass/structlunion 43 error C2228: left of .ToString must have dass/structfunion 344 error C2061: syntax eror : identifier Form 1 345 error C2601: Goldfish::GetinventoryNumber': local function definitions are ilegal OfficeSupply.app Supply.app Supply.app Supply.app Supply.app Supply.app Supply.qpp Supply.app Supply.app upply.cpp 16 46 error C2601: Goldifich::GetGoldfishType': local function definitions are ilegel 347 error C2801: Goldfish::GetPrice: local function definitions are illegal 48 error C2601: Goldfich::Display: local function definitions are legal * 49 error C2059: syntax error : * 50 error C2059: syntax error : * s 1 error C2059: syntax error : 352 error C2059 syntax error:T 25 35 53 error C 1075: end of file found before the left brace .(' at 'Supply.cpp(46), was matched 54 IntellSense: a function type involving a generic parameter cannot have an ellpsis parameter 21 r, 55 Intelsense: functon type involving genenc parameter cannot have an elpas parameter 56 IntellSense: Inkage speofication is incompatble with previous bsearch s (dedared at Ine 426) stdib.hExplanation / Answer
From the screenshot of the ‘errors’ attached:
It would be better if the error screenshot page is made more clearly visible
Multiple ; and brackets are missing in several line nos specified.
Undeclared variables like NumberInputBox, TypeInputBox, and many of these kind needs to be declared before use.
From the error ‘private’ it seems an unauthorized access to private data is being tried to be done outside the class.
void and all other return types, etc should be written in all lower case. Mind it C++ is a case sensitive language.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.