Jump to content

Hi there so I need some help which C++ GUI programming. So this semester we jumped to GUI and all we got is how to add button label and etc... and jumped to vector, dynamic array and etc... So now i need to make program which GUI. So what i'm trying to do is Load file and there are label which contains text("No files loaded") and needs to read file get data and add file name in label, but i get error and don't know why.

 

Here is the code:

private: System::Void atidarytiFailaToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)	{		openFileDialog1->DefaultExt = ".txt";		openFileDialog1->Filter = "Text files";		if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK && openFileDialog1->FileName->Length > 0)		{			String^ dfv;			dfv = openFileDialog1->FileName;			richTextBox1->LoadFile(dfv, RichTextBoxStreamType::PlainText);			string dfvs;			StringTostring(dfv, dfvs);			Duomenys(info, dfvs);			label2->Text = dfv;		}	}

And maybe someone knows where i could find more info about GUI ?

Link to comment
https://linustechtips.com/topic/312736-visual-studio-c-gui-forms/
Share on other sites

Link to post
Share on other sites

OK solved the error seemed that i attempted to read different file, which made my data reading function to go nuts. And another question is it possible to spawn labels on code or should i create empty labels and then add text then different files load. 

Link to post
Share on other sites

 

And another question is it possible to spawn labels on code or should i create empty labels and then add text then different files load. 

 

Should be. I haven't used C++ but using C# it would be done like so.

Label label1 = new Label();// fill out any properties for label1this.Controls.Add(label1); // "this" being the GUI form

It might be similar for you seeing as it looks like you're using C++ with the .NET framework.

Link to post
Share on other sites

OK so i used rich text box. Now i have one question. So i get data in to container. So i want a button which clears its data. But not sure how probably which destructor I guess but how to run destructor in form 

 

Here is the code:

 

MainForm.h

#pragma once#include <string>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include "Firma.h"using namespace std;namespace Labalatorinis {	using namespace System;	using namespace System::ComponentModel;	using namespace System::Collections;	using namespace System::Windows::Forms;	using namespace System::Data;	using namespace System::Drawing;	/* ---------- Konvertuoja eilute s (String ^) i os (string) ---------- */	void StringTostring(String ^ s, string & os)	{		using namespace Runtime::InteropServices;		const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();		os = chars;		Marshal::FreeHGlobal(IntPtr((void*)chars));	}	/* ------------------------------------------------------------------- */	/* ------------- Skaitomi pradiniai duomenys i objekta R ------------- */	void Duomenys(Firma *R, string CDfv)	{		ifstream fd(CDfv.c_str());		string pav, pv, ma, nu, da, sp;		int ri;		Taksistas A;		Taksi B;		getline(fd, pav);		while (!fd.eof()) // kol yra duomenu		{			getline(fd, pv, ','); fd >> ws; 			getline(fd, ma, ','); fd >> ws; 			getline(fd, nu, ','); fd >> ws;			getline(fd, da, ','); fd >> ws; 			getline(fd, sp, ','); fd >> ri; 			fd.ignore();			A.DetiTaks(pv, ma, nu, da, sp, ri);			B.DetiTaksista(A, pav);		}		R->DetiTaksi(B);		fd.close();	}	/* ------------------------------------------------------------------- */	/* ------------------------------------------------------------------- */	void PathToFile(string & eil)	{		int ind = -1;		ind = eil.find_last_of("/\\");		if (ind != string::npos)		{			eil = eil.substr(ind + 1);		}	}	/* ------------------------------------------------------------------- */	/* ------------------ Spausdinami objekto R duomenys ----------------- */	string Spauzdinti(Firma *R)	{		stringstream srautas;		for (int i = 0; i < R->ImtiN(); i++)		{			srautas << R->ImtiTaksi(i).Spauzdinti() << endl;		}		return srautas.str();	}	/* ------------------------------------------------------------------- */	/// <summary>	/// Summary for MainForm	/// </summary>	public ref class MainForm : public System::Windows::Forms::Form	{	public:		MainForm(void)		{			/* ----------- Constructor ----------- */			InitializeComponent();			info = new Firma;			infoc = new Firma;			/* -----------     End     ----------- */		}		/* ----------- Public ----------- */		/* -----------  End   ----------- */	protected:		/* ----------- Protected ----------- */		/* -----------    End    ----------- */		~MainForm()		{			if (components)			{				/* ----------- Destructor ----------- */				delete components;				delete info;				delete infoc;				/* -----------     End    ----------- */			}		}	private: System::Windows::Forms::MenuStrip^  menuStrip1;	protected:	private: System::Windows::Forms::ToolStripMenuItem^  failasToolStripMenuItem;	private: System::Windows::Forms::ToolStripMenuItem^  atidarytiFailaToolStripMenuItem;	private: System::Windows::Forms::ToolStripMenuItem^  issaugotiFailaToolStripMenuItem;	private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator1;	private: System::Windows::Forms::ToolStripMenuItem^  baigtiToolStripMenuItem;	private: System::Windows::Forms::OpenFileDialog^  openFileDialog1;	private: System::Windows::Forms::SaveFileDialog^  saveFileDialog1;	private: System::Windows::Forms::RichTextBox^  richTextBox1;	private:		/* ----------- Private ----------- */		Firma *info, *infoc;	private: System::Windows::Forms::Label^  label1;	private: System::Windows::Forms::RichTextBox^  richTextBox2;	private: System::Windows::Forms::ToolStripMenuItem^  redaguotiToolStripMenuItem;	private: System::Windows::Forms::ToolStripMenuItem^  pradiniaiToolStripMenuItem;	private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator2;	private: System::Windows::Forms::ToolStripMenuItem^  eksplotacijaToolStripMenuItem;	private: System::Windows::Forms::ToolStripMenuItem^  spalvaToolStripMenuItem;	private: System::Windows::Forms::ToolStripMenuItem^  sarasasToolStripMenuItem;	private: System::Windows::Forms::ToolStripMenuItem^  naujasToolStripMenuItem;			 /* -----------   End   ----------- */		System::ComponentModel::Container ^components;#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->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());			this->failasToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());			this->atidarytiFailaToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());			this->issaugotiFailaToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());			this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());			this->baigtiToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());			this->redaguotiToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());			this->pradiniaiToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());			this->toolStripSeparator2 = (gcnew System::Windows::Forms::ToolStripSeparator());			this->eksplotacijaToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());			this->spalvaToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());			this->sarasasToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());			this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());			this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());			this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());			this->label1 = (gcnew System::Windows::Forms::Label());			this->richTextBox2 = (gcnew System::Windows::Forms::RichTextBox());			this->naujasToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());			this->menuStrip1->SuspendLayout();			this->SuspendLayout();			// 			// menuStrip1			// 			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {				this->failasToolStripMenuItem,					this->redaguotiToolStripMenuItem			});			this->menuStrip1->Location = System::Drawing::Point(0, 0);			this->menuStrip1->Name = L"menuStrip1";			this->menuStrip1->Size = System::Drawing::Size(873, 24);			this->menuStrip1->TabIndex = 0;			this->menuStrip1->Text = L"menuStrip1";			// 			// failasToolStripMenuItem			// 			this->failasToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(5) {				this->naujasToolStripMenuItem,					this->atidarytiFailaToolStripMenuItem, this->issaugotiFailaToolStripMenuItem, this->toolStripSeparator1, this->baigtiToolStripMenuItem			});			this->failasToolStripMenuItem->Name = L"failasToolStripMenuItem";			this->failasToolStripMenuItem->Size = System::Drawing::Size(48, 20);			this->failasToolStripMenuItem->Text = L"Failas";			// 			// atidarytiFailaToolStripMenuItem			// 			this->atidarytiFailaToolStripMenuItem->Enabled = false;			this->atidarytiFailaToolStripMenuItem->Name = L"atidarytiFailaToolStripMenuItem";			this->atidarytiFailaToolStripMenuItem->Size = System::Drawing::Size(152, 22);			this->atidarytiFailaToolStripMenuItem->Text = L"Prideti faila...";			this->atidarytiFailaToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::atidarytiFailaToolStripMenuItem_Click);			// 			// issaugotiFailaToolStripMenuItem			// 			this->issaugotiFailaToolStripMenuItem->Enabled = false;			this->issaugotiFailaToolStripMenuItem->Name = L"issaugotiFailaToolStripMenuItem";			this->issaugotiFailaToolStripMenuItem->Size = System::Drawing::Size(152, 22);			this->issaugotiFailaToolStripMenuItem->Text = L"Issaugoti faila..";			this->issaugotiFailaToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::issaugotiFailaToolStripMenuItem_Click);			// 			// toolStripSeparator1			// 			this->toolStripSeparator1->Name = L"toolStripSeparator1";			this->toolStripSeparator1->Size = System::Drawing::Size(149, 6);			// 			// baigtiToolStripMenuItem			// 			this->baigtiToolStripMenuItem->Name = L"baigtiToolStripMenuItem";			this->baigtiToolStripMenuItem->Size = System::Drawing::Size(152, 22);			this->baigtiToolStripMenuItem->Text = L"Baigti";			this->baigtiToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::baigtiToolStripMenuItem_Click);			// 			// redaguotiToolStripMenuItem			// 			this->redaguotiToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(5) {				this->pradiniaiToolStripMenuItem,					this->toolStripSeparator2, this->eksplotacijaToolStripMenuItem, this->spalvaToolStripMenuItem, this->sarasasToolStripMenuItem			});			this->redaguotiToolStripMenuItem->Name = L"redaguotiToolStripMenuItem";			this->redaguotiToolStripMenuItem->Size = System::Drawing::Size(73, 20);			this->redaguotiToolStripMenuItem->Text = L"Redaguoti";			// 			// pradiniaiToolStripMenuItem			// 			this->pradiniaiToolStripMenuItem->Enabled = false;			this->pradiniaiToolStripMenuItem->Name = L"pradiniaiToolStripMenuItem";			this->pradiniaiToolStripMenuItem->Size = System::Drawing::Size(152, 22);			this->pradiniaiToolStripMenuItem->Text = L"Pradiniai";			this->pradiniaiToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::pradiniaiToolStripMenuItem_Click);			// 			// toolStripSeparator2			// 			this->toolStripSeparator2->Name = L"toolStripSeparator2";			this->toolStripSeparator2->Size = System::Drawing::Size(133, 6);			// 			// eksplotacijaToolStripMenuItem			// 			this->eksplotacijaToolStripMenuItem->Enabled = false;			this->eksplotacijaToolStripMenuItem->Name = L"eksplotacijaToolStripMenuItem";			this->eksplotacijaToolStripMenuItem->Size = System::Drawing::Size(152, 22);			this->eksplotacijaToolStripMenuItem->Text = L"Eksplotacija";			this->eksplotacijaToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::eksplotacijaToolStripMenuItem_Click);			// 			// spalvaToolStripMenuItem			// 			this->spalvaToolStripMenuItem->Enabled = false;			this->spalvaToolStripMenuItem->Name = L"spalvaToolStripMenuItem";			this->spalvaToolStripMenuItem->Size = System::Drawing::Size(152, 22);			this->spalvaToolStripMenuItem->Text = L"Spalva";			this->spalvaToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::spalvaToolStripMenuItem_Click);			// 			// sarasasToolStripMenuItem			// 			this->sarasasToolStripMenuItem->Enabled = false;			this->sarasasToolStripMenuItem->Name = L"sarasasToolStripMenuItem";			this->sarasasToolStripMenuItem->Size = System::Drawing::Size(152, 22);			this->sarasasToolStripMenuItem->Text = L"Sarasas";			// 			// openFileDialog1			// 			this->openFileDialog1->FileName = L"openFileDialog1";			// 			// richTextBox1			// 			this->richTextBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)				| System::Windows::Forms::AnchorStyles::Left)				| System::Windows::Forms::AnchorStyles::Right));			this->richTextBox1->BackColor = System::Drawing::SystemColors::Control;			this->richTextBox1->BorderStyle = System::Windows::Forms::BorderStyle::None;			this->richTextBox1->Font = (gcnew System::Drawing::Font(L"Courier New", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,				static_cast<System::Byte>(0)));			this->richTextBox1->Location = System::Drawing::Point(12, 49);			this->richTextBox1->Name = L"richTextBox1";			this->richTextBox1->Size = System::Drawing::Size(712, 462);			this->richTextBox1->TabIndex = 1;			this->richTextBox1->Text = L"";			// 			// label1			// 			this->label1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)				| System::Windows::Forms::AnchorStyles::Right));			this->label1->AutoSize = true;			this->label1->Location = System::Drawing::Point(727, 33);			this->label1->Name = L"label1";			this->label1->Size = System::Drawing::Size(80, 13);			this->label1->TabIndex = 2;			this->label1->Text = L"Duomenu failai:";			// 			// richTextBox2			// 			this->richTextBox2->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)				| System::Windows::Forms::AnchorStyles::Right));			this->richTextBox2->BackColor = System::Drawing::SystemColors::Control;			this->richTextBox2->BorderStyle = System::Windows::Forms::BorderStyle::None;			this->richTextBox2->Location = System::Drawing::Point(730, 49);			this->richTextBox2->Name = L"richTextBox2";			this->richTextBox2->ScrollBars = System::Windows::Forms::RichTextBoxScrollBars::None;			this->richTextBox2->Size = System::Drawing::Size(131, 205);			this->richTextBox2->TabIndex = 3;			this->richTextBox2->Text = L"Failu nera";			// 			// naujasToolStripMenuItem			// 			this->naujasToolStripMenuItem->Name = L"naujasToolStripMenuItem";			this->naujasToolStripMenuItem->Size = System::Drawing::Size(152, 22);			this->naujasToolStripMenuItem->Text = L"Naujas";			this->naujasToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::naujasToolStripMenuItem_Click);			// 			// MainForm			// 			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;			this->ClientSize = System::Drawing::Size(873, 523);			this->Controls->Add(this->richTextBox2);			this->Controls->Add(this->label1);			this->Controls->Add(this->richTextBox1);			this->Controls->Add(this->menuStrip1);			this->MainMenuStrip = this->menuStrip1;			this->Name = L"MainForm";			this->ShowIcon = false;			this->Text = L"U1-21. Taksi";			this->menuStrip1->ResumeLayout(false);			this->menuStrip1->PerformLayout();			this->ResumeLayout(false);			this->PerformLayout();		}#pragma endregion	private: System::Void atidarytiFailaToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)	{		openFileDialog1->DefaultExt = ".txt";		openFileDialog1->Filter = "TXT failai|*.txt";		if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK && openFileDialog1->FileName->Length > 0)		{			String^ dfv;			String^ txb;			dfv = openFileDialog1->FileName;			string dfvs;			StringTostring(dfv, dfvs);			Duomenys(info, dfvs);			PathToFile(dfvs);			dfv = gcnew String(dfvs.c_str());			txb = richTextBox2->Text;			if (txb != "Failu nera")			{				dfv = txb + "\n" + dfv;			}			richTextBox2->Text = dfv;		}	}	private: System::Void issaugotiFailaToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)	{		saveFileDialog1->DefaultExt = ".txt";		saveFileDialog1->Filter = "TXT failai|*.txt";		if (saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK && saveFileDialog1->FileName->Length > 0)		{			String^ rfv;			rfv = saveFileDialog1->FileName;			string rfvs;			StringTostring(rfv, rfvs);			richTextBox1->SaveFile(rfv, RichTextBoxStreamType::PlainText);		}	}	private: System::Void baigtiToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)	{		Close();	}	private: System::Void pradiniaiToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)	{		String^ dfv;		string dfvs;		String^ txb;		txb = richTextBox1->Text;		dfv = txb + "\n Pradiniai duomenys:\n\n";		dfvs = Spauzdinti(info);		dfv = dfv + gcnew String(dfvs.c_str());		richTextBox1->Text = dfv;	}	private: System::Void eksplotacijaToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) 	{		String^ dfv;		String^ txb;		string dfvs;		int    rida;		txb = richTextBox1->Text;		info->Eksplot(dfvs, rida);		dfv = txb + "\n Automobilis eksploatuojamas intensyviausiai:\n";		dfv = dfv + gcnew String(dfvs.c_str()) + " - " + System::Convert::ToString(rida) + " (tukst. km)";		richTextBox1->Text = dfv;	}	private: System::Void spalvaToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) 	{		String^ dfv;		String^ txb;		string dfvs;		txb = richTextBox1->Text;		dfvs = info->Spalva();		dfv = txb + "\n Spalva kuria turi tik viena firma:\n";		dfv = dfv + gcnew String(dfvs.c_str());		richTextBox1->Text = dfv;	}	private: System::Void naujasToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)	{		atidarytiFailaToolStripMenuItem->Enabled = true;		richTextBox2->Text = "Failu nera";		info	}};} 
#include "MainForm.h"/*-------------------------------------------------------------------------------*/using namespace System;using namespace System::Windows::Forms;[STAThread]int main(array<System::String ^> ^args){	Application::EnableVisualStyles();	Application::SetCompatibleTextRenderingDefault(false);	Labalatorinis::MainForm form;	Application::Run(%form);}/*-------------------------------------------------------------------------------*/ 
#pragma once#include "Taksi.h"#include <string>#include <sstream>#include <iomanip>class Firma{public:	static const int Cd = 5;private:	Taksi *Fi;	int n;	int nmax;	void KeistiMasyvoDydi(int kiek);public:	Firma(int nmx = 0);	~Firma();	void DetiTaksi(Taksi & taks);	Taksi ImtiTaksi(int ind) { return Fi[ind]; }	int ImtiN() { return n; }	void Eksplot(string & mar, int & rid);	string Spalva();}; 
#include "Firma.h"#include <string>#include <sstream>#include <iomanip>Firma::Firma(int nmx) : Fi(nullptr), n(0), nmax(nmx){	if (nmax > 0)	{		Fi = new Taksi[nmax];	}}Firma::~Firma(){	if (Fi)	{		delete[] Fi;	}}void Firma::KeistiMasyvoDydi(int kiek){	if (kiek > nmax)	{		Taksi *Fnaujas = new Taksi[kiek];		for (int i = 0; i < n; i++)		{			Fnaujas[i] = Fi[i];		}		delete[] Fi;		Fi = Fnaujas;		nmax = kiek;	}	else	{		if (kiek < nmax)		{			Taksi *Fnaujas = new Taksi[kiek];			for (int i = 0; i < kiek; i++)			{				Fnaujas[i] = Fi[i];			}			delete[] Fi;			Fi = Fnaujas;			n = nmax = kiek;		}	}}void Firma::DetiTaksi(Taksi & taks){	if (n == nmax)	{		KeistiMasyvoDydi(n + Cd);	}	Fi[n] = taks;	n++;}void Firma::Eksplot(string & mar, int & rid){	mar = "";	rid = 0;	for (int i = 0; i < n; i++)	{		for (int j = 0; j < Fi[i].ImtiN(); j++)		{			if (Fi[i].ImtiTaksista(j).ImtiRid() > rid)			{				rid = Fi[i].ImtiTaksista(j).ImtiRid();				mar = Fi[i].ImtiTaksista(j).ImtiMar();			}		}	}}string Firma::Spalva(){	stringstream eil;	bool yra;	for (int i = 0; i < n; i++)	{		for (int k = 0; k < Fi[i].ImtiN(); k++)		{			yra = false;			for (int j = 0; j < n; j++)			{				for (int l = 0; l < Fi[j].ImtiN() && j != i; l++)				{					if (Fi[i].ImtiTaksista(k).ImtiSpa() == Fi[j].ImtiTaksista(l).ImtiSpa())					{						yra = true;					}				}			}			if (yra == false)			{				eil << left << setw(12) << Fi[i].ImtiP() << " - " << right << setw(14) << Fi[i].ImtiTaksista(k).ImtiSpa() << endl;			}		}	}	return eil.str();} 
#pragma once#include <string>#include <sstream>#include <iomanip>#include "Taksistas.h"class Taksi{public:	static const int Cd = 5;private:	Taksistas *Ta;	int n;	int nmax;	string pav;	void KeistiMasyvoDydi(int kiek);	int ilgis[6];public:	Taksi(int nmx = 0);   //~Taksi();   void DetiTaksista(Taksistas & taks, string pv);   Taksistas ImtiTaksista(int ind) { return Ta[ind]; }   int    ImtiN() { return   n; }   string ImtiP() { return pav; }   string Spauzdinti();}; 
#include "Taksi.h"#include <string>#include <sstream>#include <iomanip>#include <iostream>using namespace std;Taksi::Taksi(int nmx) : Ta(nullptr), n(0), nmax(nmx), pav(""){	if (nmax > 0)	{		Ta = new Taksistas[nmax];	}}/*Taksi::~Taksi(){	if (Ta)	{		delete[] Ta;	}}*/void Taksi::KeistiMasyvoDydi(int kiek){	if (kiek > nmax)	{		Taksistas *Tnaujas = new Taksistas[kiek];		for (int i = 0; i < n; i++)		{			Tnaujas[i] = Ta[i];		}		delete[] Ta;		Ta = Tnaujas;		nmax = kiek;	}	else	{		if (kiek < nmax)		{			Taksistas *Tnaujas = new Taksistas[kiek];			for (int i = 0; i < kiek; i++)			{				Tnaujas[i] = Ta[i];			}			delete[] Ta;			Ta = Tnaujas;			n = nmax = kiek;		}	}}void Taksi::DetiTaksista(Taksistas & taks, string pv){	if (n == nmax)	{		KeistiMasyvoDydi(n + Cd);	}	Ta[n] = taks;	pav = pv;	n++;}string Taksi::Spauzdinti(){	stringstream eil;	eil << "   " << pav << "\n\n";	for (int i = 0; i < n; i++)	{		eil << Ta[i].Spauzdinti();	}	return eil.str();} 
#pragma once#include <string>#include <sstream>#include <iomanip>using namespace std;class Taksistas{private:	string pav; // Vairuotojo pavarde.	string mar; // Masinos marke.	string num; // Masinos valstybinis numeris.	string dat; // Masinos pagaminimo metai.	string spa; // Masinos spalva.	int    rid; // Rida (tuks. km) per metus.public:	Taksistas() : pav(""), mar(""), num(""), dat(""), spa(""), rid(0) {}	Taksistas(string pv, string ma, string nu, string da, string sp, int ri);	void DetiTaks(string pav, string mar, string num, string dat, string spa, int rid);	string ImtiPav() { return pav; }	string ImtiMar() { return mar; }	string ImtiNum() { return dat; }	string ImtiDat() { return dat; }	string ImtiSpa() { return spa; }	int    ImtiRid() { return rid; }	string Spauzdinti();}; 
#include "Taksistas.h"#include <string>#include <sstream>#include <iomanip>void Taksistas::DetiTaks(string pav, string mar, string num, string dat, string spa, int rid){	Taksistas::pav = pav;	Taksistas::mar = mar;	Taksistas::num = num;	Taksistas::dat = dat;	Taksistas::spa = spa;	Taksistas::rid = rid;}string Taksistas::Spauzdinti(){	stringstream eil;	eil <<  left << setw(15) << pav;	eil <<  left << setw(12) << mar;	eil <<  left << setw(8)  << num;	eil <<  left << setw(11) << dat;	eil <<  left << setw(14) << spa;	eil << right << setw(4)  << rid; 	eil << endl;	return eil.str();} 
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×