Samarqand davlat universiteti raqamli texnologiyalar fakulteti dasturiy injiniring yo




Download 124.43 Kb.
bet2/2
Sana08.07.2022
Hajmi124.43 Kb.
#24829
1   2
Bog'liq
Shalola-shodmonova-dasturlash
Diyonat, Odil Yoqubov, 2 5285530494128101228, hffpN0EruKkAOHdWjgmWesI50OHSYnlFNJkkg5Tm, Ma\'lumotlar bazasini boshqarish sistemasi (A.Sattorov), b41d5475c6b85e36a24e18d9ca246ed2 Qiziqarli matematika va olimpiada masalalari, Сердобольская Чуличков Пособие Теорвер, suv test, Multimedia tarmoqlari, 1678635060 (1), Vino kislotasi, ATT Kurs mavzulari, Multisim modellashtirish dasturi, Rustam, Презентация Microsoft PowerPoint kons
2-masala
. SportClub ajdod sinfini hosil qiling. Uning jamoa nomi, murabbiy nomi kabi xossalari bo’lsin. FootballClub, BasketballClub avlod sinflarini hosil qilib, uning tarkibida jamoaning sportchilarga to’laydigan yillik summasini hisoblaydigan metod aniqlang.
Dastur kodi:
#include
#include
#include
using namespace std;
class SportClub {
protected :
string m_team;
string m_coach;
public:
SportClub(string team, string coach) {
this->m_team=team;
this->m_coach=coach;
}
string getTeam(){ return m_team; }
string getCoach(){ return m_coach; }

};

class FootballClub:public SportClub {


protected:
vectormoney;
public:
FootballClub(string team, string coach, vectormoney): SportClub(team, coach) {
this->money=money;
}
int getSalary(){
int month = 12, summa = 0;
for (int i = 0; i < month; i++) {
summa += this->money[i];
}
return summa;
}
int getMonthMoney() {
int month = 12, max = 0;
for (int i = 0; i < month; i++) {
if(this->money[i] > max)
max = this->money[i];
}
int a;
for (int i = 0; i < month; i++) {
if(this->money[i] == max)
a=i+1;
}
switch(a){
case 1:cout<<"Yanvar : "; break;
case 2:cout<<"Fevral : "; break;
case 3:cout<<"Mart : "; break;
case 4:cout<<"Aprel : "; break;
case 5:cout<<"May : "; break;
case 6:cout<<"Iyun : "; break;
case 7:cout<<"Iyul : "; break;
case 8:cout<<"Avgust : "; break;
case 9:cout<<"Sentabr : "; break;
case 10:cout<<"Oktabr : "; break;
case 11:cout<<"Noyabr : "; break;
case 12:cout<<"Dekabr : "; break;
default : cout<<"xato"; break;
}
return max;
}
};
int main()
{
cout<<"Futbol jamoasi, murabbiyni va futbolchilar maoshini kiriting!!!!"<string team,coach;
cout<<"Jamoa : ";
getline(cin, team);
cout<<"Murabbiy : ";
getline(cin, coach);
vector money;
int month=12, temp=0;
for(int i = 0; i < month; i++)
{
cout<cin>>temp;
money.push_back(temp);
}
FootballClub obj1(team,coach, money);
cout<<"Yillik maosh : "<return 0;}
Dastur natijasi:


3-masala
BubbleSort algoritmini shablonlar orqali tuzing
Dastur codi:
#include
#include
using namespace std;
template
class BubbleSort
{
int m_n;
vector m_V;
public:
BubbleSort(vector V, int n){
m_V = V;
m_n = n;
}
void setSorted(){
for (int i = 0; i < m_n - 1; i++)
for (int j = m_n - 1; i < j; j--)
if (m_V[j] < m_V[j - 1])
swap(m_V[j], m_V[j - 1]);

}

vector getArr(){


return m_V;
}
};

int main()


{
int n;
float temp;
vector V;
cout<<"Elementlar soni : ";cin>> n;
if(n > 100){
cout<<"Elementlar soni ko'p";
}
else{
for(int i=0;icout<<"Arr["<>temp;
V.push_back(temp);
}

n = V.size();


BubbleSort obj(V, n);
obj.setSorted();
V = obj.getArr();
cout << " Sorted Array : ";
for (int i = 0; i < n; i++)
cout << V[i] << " ";
cout << endl;
return 0;
}
}
Dastur natijasi:


4-masala
. Insonning tug’ilgan sanasi ma’lum. Uning yoshini, necha oy yashaganini chop eting. Tug’ilgan sana noto’g’ri kiritilishi va tiplar bilan xatolar istisnoni generatsiya qilishga olib keladi.
Dastur codi:
#include
using namespace std;
class Human
{
private:
int m_day;
int m_month;
int m_year;
int m_nday;
int m_nmonth;
int m_nyear;
public:
class DayEx {};
class MonthEx {};
class YearEx {};
class DayNowEx {};
class MonthNowEx {};
class YearNowEx {};
Human()
{
m_day=0;
m_month=0;
m_year=0;
m_nday=0;
m_nmonth=0;
m_nyear=0;
}

Human(int day,int month,int year)


{
if(day<=0||day >31)
throw DayEx();
if((day-int(day)>0))
throw DayEx();
if(month-int(month)>0)
throw MonthEx();
if(year-int(year)>0)
throw YearEx();
m_day=day;
m_month=month;
m_year=year;
}
void setDay(int day)
{
if((day-int(day)>0))
{
throw DayEx();
}
if(day<=0||day >31)
throw DayEx();
m_day=day;
}
void setMonth(int month)
{
if((month-int(month)>0))
{
throw MonthEx();
}
if(month>12||month<=0)
throw MonthEx();
m_month=month;
}
void setYear(int year)
{
if((year-int(year)>0))
{
throw YearEx();
}
if(year<=0)
throw YearEx();
m_year=year;
}
void setNday(int day)
{
if((day-int(day)>0))
{
throw DayNowEx();
}
if(day<=0||day >31)
throw DayNowEx();
m_nday=day;
}
void setNmonth(int month)
{
if((month-int(month)>0))
{
throw MonthNowEx();
}
if(month>12||month<=0)
throw MonthNowEx();
m_nmonth=month;
}
void setNyear(int year)
{
if((year-int(year)>0))
{
throw YearNowEx();
}
if(year<=0)
throw YearNowEx();
m_nyear=year;
}
void getInformation()
{
if(m_nmonth>m_month)
{
cout<<" Siz "<cout<<" yil-u "<}
else
cout<<" Siz "<cout<<" yil-u "<}
};
int main()
{
try
{
int a,b,c,d,m,nyear;
Human obj;
cout<<"Tug'ilgan kunnizni kiriting : ";
cin>>a;
obj.setDay(a);
cout<<"Tug'ilgan oyizni kiriting : ";
cin>>b;
obj.setMonth(b);
cout<<"Tug'ilgan yilizni kiriting : ";
cin>>c;
obj.setYear(c);
cout<<"Hozirgi kunni kiriting : ";
cin>>d;
obj.setNday(d);
cout<<"Hozirgi oyni kiriting : ";
cin>>m;
obj.setNmonth(m);
cout<<"Hozirgi yilni kiriting : ";
cin>>nyear;
obj.setNyear(nyear);
obj.getInformation();
}
catch (Human::DayEx)
{
cerr<<"Kun noto'g'ri kiritilgan. ";
}
catch (Human::MonthEx)
{
cerr<<"Oy noto'g'ri kiritilgan. ";
}
catch (Human::YearEx)
{
cerr<<"Yil noto'g'ri kiritilgan. ";
}
catch (Human::DayNowEx)
{
cerr<<"Hozirgi kun noto'g'ri kiritilgan. ";
}
catch (Human::MonthNowEx)
{
cerr<<"Hozirgi oy noto'g'ri kiritilgan. ";
}
catch (Human::YearNowEx)
{
cerr<<"Hozirgi yil noto'g'ri kiritilgan. ";
}
return 0;
}
Dastur natijasi:


5-masala
Talabaning baholari faylga yozilgan. Bu baholar asosida talaba GPA sini hisoblovchi metod mavjud bo’lgan Student sinfini hosil qiling. N ta talabaning K ta fandan olgan bahosi faylda yozilgan deb hisoblang
Dastur codi:
#include
#include
using namespace std;

class Student{


int s_subject;
int *s_gpa;
int *s_grade;
string s_name;
string s_filegpa;
string s_baho;
public:
Student(){
s_name="";
s_filegpa="GPA.txt";
s_baho="BAHO.txt";
s_grade=0;
s_gpa=0;
s_subject=0;
}
Student(string baho, string gpa,string name,int sub){
s_name=name;
s_baho=baho;
s_subject=sub;
s_filegpa=gpa;
}

float GPA(){


if(s_subject!=0){
float sum=0,multi=0;
for(int i=0; imulti+=s_gpa[i]*s_grade[i];
sum+=s_gpa[i];
}
return multi/sum;
}
return 0;
}

void Baho(ifstream &baho){


if(!baho.is_open()){
baho.open("BAHO.txt");
}
char b; int j=0,m=0,k;
s_grade=new int[s_subject];
for(int i=0; ibaho >>s_grade[i];
}
}

void subjectGpa(){


char b; int j=0,m=0;
ifstream s_gpafile;
s_gpafile.open(s_filegpa);
s_gpa=new int[s_subject];
for(int i=0; is_gpafile >>s_gpa[i];
}
s_gpafile.close();
}

void setName(string name){


s_name=name;
}

string getName(){


return s_name;
}

void getGrade(){


for(int i=0; i cout << s_grade[i] << endl;
}
}

void changeStatic(int x){


s_subject=x;
}

~Student(){


delete[] s_grade;
}
};

int main(int argc, char *argv[])


{
int n,k; string name;
cout <<"Talaba soni : "; cin >> n;
cout << "Fan soni : "; cin >> k;
ifstream baho("BAHO.txt");

Student all[n];

for(int i=0; icout <<"ism : ";
cin >> name;
all[i].changeStatic(k);
all[i].setName(name);
all[i].Baho(baho);
all[i].subjectGpa();
}
baho.close();

for(int i=0; i
cout <<"\nTalaba ismi " << all[i].getName()<<" GPA=" << all[i].GPA()<}

return 0;


}

Dastur natijasi:




Download 124.43 Kb.
1   2




Download 124.43 Kb.

Bosh sahifa
Aloqalar

    Bosh sahifa



Samarqand davlat universiteti raqamli texnologiyalar fakulteti dasturiy injiniring yo

Download 124.43 Kb.