















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The implementation of a singly linked list in c++ using templates for managing student data. The linked list includes methods for adding nodes, deleting nodes, sorting nodes based on roll number and alphabetical order, and searching for a node based on roll number.
Typology: Exercises
1 / 23
This page cannot be seen from the preview
Don't miss anything!
















#pragma once #include
template
template
template
template
template
template
template
temp = temp->next; } }
template
template
template
template
template
template
namespace Project2 {
using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing;
///
protected: ///
private: System::Windows::Forms::ListView^ listView2; private: System::Windows::Forms::ColumnHeader^ columnHeader4; private: System::Windows::Forms::ColumnHeader^ columnHeader5; private: System::Windows::Forms::ColumnHeader^ columnHeader6; private: System::Windows::Forms::Button^ button6; private: System::Windows::Forms::Button^ button5; private: System::Windows::Forms::Button^ button4; private: System::Windows::Forms::Label^ label6; private: System::Windows::Forms::Button^ button7;
private: ///
#pragma region Windows Form Designer generated code ///
this->label3->AutoSize = true; this->label3->Location = System::Drawing::Point(21, 141); this->label3->Name = L"label3"; this->label3->Size = System::Drawing::Size(102, 13); this->label3->TabIndex = 6; this->label3->Text = L"Enter the Descipline"; // // label // this->label2->AutoSize = true; this->label2->Location = System::Drawing::Point(21, 93); this->label2->Name = L"label2"; this->label2->Size = System::Drawing::Size(81, 13); this->label2->TabIndex = 5; this->label2->Text = L"Enter the Name"; // // textBox // this->textBox3->Location = System::Drawing::Point(187, 138); this->textBox3->Name = L"textBox3"; this->textBox3->Size = System::Drawing::Size(129, 20); this->textBox3->TabIndex = 4; // // textBox // this->textBox2->Location = System::Drawing::Point(187, 90); this->textBox2->Name = L"textBox2"; this->textBox2->Size = System::Drawing::Size(129, 20); this->textBox2->TabIndex = 3; // // button // this->button1->Location = System::Drawing::Point(202, 193); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(95, 34); this->button1->TabIndex = 2; this->button1->Text = L"Enter"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click); // // tabPage // this->tabPage2->Controls->Add(this->button2); this->tabPage2->Controls->Add(this->label4); this->tabPage2->Controls->Add(this->textBox4); this->tabPage2->Controls->Add(this->listView1); this->tabPage2->Location = System::Drawing::Point(4, 22); this->tabPage2->Name = L"tabPage2"; this->tabPage2->Padding = System::Windows::Forms::Padding(3); this->tabPage2->Size = System::Drawing::Size(463, 290); this->tabPage2->TabIndex = 1; this->tabPage2->Text = L"Search"; this->tabPage2->UseVisualStyleBackColor = true; // // button // this->button2->Location = System::Drawing::Point(95, 146);
this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(100, 30); this->button2->TabIndex = 3; this->button2->Text = L"Enter"; this->button2->UseVisualStyleBackColor = true; this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click); // // label // this->label4->AutoSize = true; this->label4->Location = System::Drawing::Point(18, 83); this->label4->Name = L"label4"; this->label4->Size = System::Drawing::Size(60, 13); this->label4->TabIndex = 2; this->label4->Text = L"Enter Roll#"; // // textBox // this->textBox4->Location = System::Drawing::Point(95, 80); this->textBox4->Name = L"textBox4"; this->textBox4->Size = System::Drawing::Size(100, 20); this->textBox4->TabIndex = 1; // // listView // this->listView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::ColumnHeader^ >(3) { this->columnHeader1, this->columnHeader2, this->columnHeader }); this->listView1->Location = System::Drawing::Point(223, 38); this->listView1->Name = L"listView1"; this->listView1->Size = System::Drawing::Size(234, 246); this->listView1->TabIndex = 0; this->listView1->UseCompatibleStateImageBehavior = false; this->listView1->View = System::Windows::Forms::View::Details; // // columnHeader // this->columnHeader1->Text = L"Roll No"; this->columnHeader1->Width = 74; // // columnHeader // this->columnHeader2->Text = L"Name"; this->columnHeader2->Width = 86; // // columnHeader // this->columnHeader3->Text = L"Descipline"; this->columnHeader3->Width = 66; // // tabPage // this->tabPage3->Controls->Add(this->button3); this->tabPage3->Controls->Add(this->textBox5); this->tabPage3->Controls->Add(this->label5);
this->button6->Click += gcnew System::EventHandler(this, &MyForm::button6_Click); // // button // this->button5->Location = System::Drawing::Point(322, 120); this->button5->Name = L"button5"; this->button5->Size = System::Drawing::Size(122, 32); this->button5->TabIndex = 3; this->button5->Text = L"By Descipline"; this->button5->UseVisualStyleBackColor = true; this->button5->Click += gcnew System::EventHandler(this, &MyForm::button5_Click); // // button // this->button4->Location = System::Drawing::Point(322, 51); this->button4->Name = L"button4"; this->button4->Size = System::Drawing::Size(122, 32); this->button4->TabIndex = 2; this->button4->Text = L"By Roll #"; this->button4->UseVisualStyleBackColor = true; this->button4->Click += gcnew System::EventHandler(this, &MyForm::button4_Click); // // label // this->label6->AutoSize = true; this->label6->Location = System::Drawing::Point(319, 9); this->label6->Name = L"label6"; this->label6->Size = System::Drawing::Size(125, 13); this->label6->TabIndex = 1; this->label6->Text = L"Choose data sort method"; // // listView // this->listView2->Columns->AddRange(gcnew cli::array< System::Windows::Forms::ColumnHeader^ >(3) { this->columnHeader4, this->columnHeader5, this->columnHeader }); this->listView2->Location = System::Drawing::Point(7, 9); this->listView2->Name = L"listView2"; this->listView2->Size = System::Drawing::Size(270, 278); this->listView2->TabIndex = 0; this->listView2->UseCompatibleStateImageBehavior = false; this->listView2->View = System::Windows::Forms::View::Details; // // columnHeader // this->columnHeader4->Text = L"Roll #"; this->columnHeader4->Width = 66; // // columnHeader // this->columnHeader5->Text = L"Name"; this->columnHeader5->Width = 118; //
// columnHeader // this->columnHeader6->Text = L"Descipline"; this->columnHeader6->Width = 83; // // button // this->button7->Location = System::Drawing::Point(353, 134); this->button7->Name = L"button7"; this->button7->Size = System::Drawing::Size(88, 26); this->button7->TabIndex = 7; this->button7->Text = L"Examples"; this->button7->UseVisualStyleBackColor = true; this->button7->Click += gcnew System::EventHandler(this, &MyForm::button7_Click); // // MyForm // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(475, 319); this->Controls->Add(this->tabControl1); this->Name = L"MyForm"; this->Text = L"MyForm"; this->tabControl1->ResumeLayout(false); this->tabPage1->ResumeLayout(false); this->tabPage1->PerformLayout(); this->tabPage2->ResumeLayout(false); this->tabPage2->PerformLayout(); this->tabPage3->ResumeLayout(false); this->tabPage3->PerformLayout(); this->tabPage4->ResumeLayout(false); this->tabPage4->PerformLayout(); this->ResumeLayout(false);
#pragma endregion private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { string roll, des, nam; msclr::interop::marshal_context context; if (textBox1->Text != ""&&textBox2->Text != ""&&textBox3->Text != "") { roll = context.marshal_as
string roll; bool flag; msclr::interop::marshal_context context; if (textBox5->Text != "") { roll = context.marshal_as
listView2->Items->Clear(); msclr::interop::marshal_context context; int x, count; count = l.getcount(); for (x = 0; x < count; x++) { String^s = context.marshal_as<String^>(l.getroll(x)); String^s1 = context.marshal_as<String^>(l.getname(x)); String^s2 = context.marshal_as<String^>(l.getdesci(x)); listView2->Items->Add(gcnew String("" + s)); listView2->Items[x]->SubItems->Add(gcnew String("" + s1)); listView2->Items[x]->SubItems->Add(gcnew String("" + s2)); } } private: System::Void button7_Click(System::Object^ sender, System::EventArgs^ e) { this->Hide(); MyForm1 ^f = gcnew MyForm1(this); f->ShowDialog(); } }; }
#pragma once #include
using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing;
///
MyForm1(Form ^a) {
this->listView1->Name = L"listView1"; this->listView1->Size = System::Drawing::Size(344, 226); this->listView1->TabIndex = 0; this->listView1->UseCompatibleStateImageBehavior = false; this->listView1->View = System::Windows::Forms::View::Details; // // columnHeader // this->columnHeader1->Text = L"Index"; // // columnHeader // this->columnHeader2->Text = L"Program Code"; this->columnHeader2->Width = 86; // // columnHeader // this->columnHeader3->Text = L"Program Name"; this->columnHeader3->Width = 193; // // button // this->button1->Location = System::Drawing::Point(12, 237); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(75, 23); this->button1->TabIndex = 1; this->button1->Text = L"Back"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &MyForm1::button1_Click); // // button // this->button2->Location = System::Drawing::Point(258, 237); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(75, 23); this->button2->TabIndex = 2; this->button2->Text = L"Show List"; this->button2->UseVisualStyleBackColor = true; this->button2->Click += gcnew System::EventHandler(this, &MyForm1::button2_Click); // // MyForm // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(345, 272); this->Controls->Add(this->button2); this->Controls->Add(this->button1); this->Controls->Add(this->listView1); this->Name = L"MyForm1"; this->Text = L"MyForm1"; this->ResumeLayout(false);
#pragma endregion private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
msclr::interop::marshal_context context; fstream file; string *str, *str1,s; int size = 0,temp,len,count=0,x=0; file.open("text_check.TXT"); if (file.is_open()) { while (!file.eof()) { getline(file, s); size++; } file.close(); str = new string[size]; str1 = new string[size]; file.open("text_check.TXT"); while (!file.eof()) { count = 0; temp = count; len = 0; getline(file, s); while (s[count] != ' ') { count++; len++; } str[x] = s.substr(temp, len); count++; temp = count; len = 0; while (s[count] != '\0') { count++; len++; } str1[x] = s.substr(temp, len); x++; } } for (x = 0; x < size; x++) { String^s = context.marshal_as<String^>(str[x]); String^s1 = context.marshal_as<String^>(str1[x]); listView1->Items->Add(gcnew String("" + (x+1))); listView1->Items[x]->SubItems->Add(gcnew String("" + s)); listView1->Items[x]->SubItems->Add(gcnew String("" + s1)); } } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { this->Hide(); b->Show(); } }; }