Je prends une classe en C++ et j'ai reçu mon premier projet. En classe, le professeur parle simplement de syntaxe, de grammaire, etc. Il ne parle jamais de l'utilisation de Visual Studio. Il nous a envoyé un fichier d'en-tête sans aucune explication et s'attend à ce que nous l'utilisions pour le projet. Je ne sais pas trop comment commencer avec ce fichier. J'ai essayé de créer un projet Visual C++ vide, en ajoutant ce fichier et en l'exécutant mais pour un, il y a une erreur de soulignement rouge partout et deux, VS dit qu'il ne peut pas trouver l'exécutable. Si quelqu'un peut m'aider à obtenir VS et/ou mon projet, je peux m'occuper de faire le programme (j'ai juste fini d'écrire le même programme en Java).Démarrer un nouveau projet avec juste un fichier d'en-tête
Ceci est le fichier d'en-tête qu'il nous a envoyé. A en juger par les apparences, il est un peu négligé.
#pragma once
namespace control2 {
using namespace System;
using namespace System::IO; // added by Zhang
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
// added by Zhang
StreamReader ^sr = gcnew StreamReader("control.txt");
this->choice=Int32::Parse(sr->ReadLine());
sr->Close();
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
int choice;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->SuspendLayout();
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 266);
this->Name = L"Form1";
this->Text = L"CS351";
this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::Form1_Paint);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
Graphics ^g = e->Graphics;
// g->Clear(BackColor);
// g->Clear(Color::Red);
for (int y = 0; y < 10; y++) {
// pick the shape based on the user's choice
switch (choice)
{
case 1: // draw rectangles
g->DrawRectangle(Pens::Black, 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10);
break;
case 2: // draw ovals
// g->DrawEllipse(Pens::Black, 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10);
g->DrawArc(Pens::Black, 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10, 0, 360);
break;
case 3: // fill rectangles
g->FillRectangle(Brushes::Red, 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10);
break;
case 4: // fill ovals
// g->FillEllipse(gcnew SolidBrush(Color::Red), 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10);
g->FillPie(gcnew SolidBrush(Color::Red), 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10, 0, 360);
break;
default: // draw lines
g->DrawLine(Pens::Black, 10 + i * 10, 60 + i * 20, 60 + i * 20, 10 + i * 10);
break;
} // end switch
} // end for
choice=(choice+1)%5;
}
};
}
Ce code n'est pas C++ ... close, mais ceux qui sont errants '^' sont vraiment déroutants. Je me demande s'il a mal saisi '&'. –
Je pense que c'est C++ - cli, n'est-ce pas? –
Ce code ne produirait pas réellement un programme. c'est juste définir des choses. Vous devrez fournir le code qui utilise réellement ce genre de choses. par exemple. le prof vous a fourni les plans, mais vous devez construire une maison en utilisant ces plans. –