0% found this document useful (0 votes)
21 views5 pages

Report Lab 1.1

Uploaded by

dea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views5 pages

Report Lab 1.1

Uploaded by

dea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

National Aviation University

Faculty of Cybersecurity, Computer and Software Engineering


Software engineering department

Basics of Programming
Laboratory work 1.1
STUDY OF DESCRIPTION AND APPLICATION OF CLASSES

Variant - 5

Prepared by:
student of SE-121 en.,
Demchuk Oksana

Accepted by:
Vasilieva M.D.

Kiev, 2022
Task
1. Learn the description of class in languages С++ and С#.
2. Study the mechanisms of creating, using and destroying objects of classes
in programming languages С++ and С#.
3. Write a program in languages C++ and С# to demonstrate examples of the
class application (choose the variant to be performed in Appendix 1)

Procedure

C++
Source.cpp
#include "String.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{
Strings *newText = new Strings("hgfedFGRAcba");
newText->sort();
newText->print();

delete newText;
return 0;
}

String.h
#pragma once
#include <iostream>
#include<string>
#include <regex>
using namespace std;

class Strings {

Kiev, 2022 Page 2


private:
string text = "";
public:

Strings(string newText)
{
for (int i = 0; i < StringLength(); i++) {
if (newText[i] > 96 && newText[i] < 123){
text += newText[i];
}
}
}
~Strings(){}

int StringLength() {
int len = 0;
while (text[len] != '\0') {
len++;
}
return len;
}

void sort()
{
char temp;
for (int i = 0; i < StringLength(); i++) {

for (int j = 0; j < StringLength() - 1; j++) {


if (text[j] > text[j + 1]) {
temp = text[j];
text[j] = text[j + 1];
text[j + 1] = temp;
}
}
}
}
void print()
{
cout << "Length is " << StringLength() << endl;
cout << "String: " << text << endl;
}

};

C#
Program.cs
using Laboratory1;

namespace MainProgram
{
class Program
{
static void Main(string[] args)
{
task();

Kiev, 2022 Page 3


}
static void task()
{
StringClass example = new StringClass("HAYshaygdFAg");
example.sortString();
Console.WriteLine("String: " + example.ToString());
Console.WriteLine("Length is " + example.StringLength());

}
}

StringClass.cs
using System.Text;
using System.Text.RegularExpressions;

namespace Laboratory1
{
class StringClass
{
private string text="";
public StringClass(string newText)
{
value=newText;
}
public int StringLength()
{
int len = 0;
foreach (char c in text)
{
len++;
}
return len;
}
public string getText()
{
return text;
}
public void sortString()
{
char temp;
StringBuilder temp2 = new StringBuilder(text);
for (int i = 0; i < StringLength(); i++)
{

for (int j = 0; j < StringLength() - 1; j++)


{
if (temp2[j] > temp2[j + 1])
{
temp = temp2[j];
temp2[j] = temp2[j + 1];
temp2[j + 1] = temp;
}
}

Kiev, 2022 Page 4


}
text = temp2.ToString();
}
public string value
{
get { return text; }
set
{

for (int i = 0; i < StringLength(); i++)


{
if (value[i] > 96 && value[i] < 123)
{
text += value[i];
}
}
}
}

~StringClass()
{

}
}
}

Conclusion

During the laboratory work I studied the description of classes, learned to create, use and destroy
the objects of classes.

Kiev, 2022 Page 5

You might also like