Answer the question
In order to leave comments, you need to log in
Error undefined reference to vyb(). How to fix case call?
The code presents data input, and then you need to sort by sorting methods: QuickSort and selection sort. But the compiler throws an undefined reference to vyb() error. How to fix the code to make case 7 work??
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <thread>
#include <fstream>
using namespace std;
FILE *fl;
typedef struct
{
char kod;
unsigned char kol; /*dlya vvoda s klaviatury menu 3*/
unsigned char mes;
} detail;
detail det[30];
int mesn;
int k;
char name[20];
int nst=0;
int menu();
void nnf();
void newf();
void spisok();
void opf();
void resc();
void resf();
void vyb();
int main()
{
while (true){
switch (menu()){
case 1: nnf(); break;
case 2: newf(); break;
case 3: spisok(); break;
case 4: opf(); break;
case 5: resc(); break;
case 6: resf(); break;
case 7 : vyb(); break;
case 8: return 0;
default: "Viberite punkt menu!";
}
puts("Press any key to continue");
getch();
system("cls");
}
}
int menu()
{
cout << "VIBERITE:" << endl;
cout << "1. Vvod file name" << endl;
cout << "2. New file" << endl;
cout << "3. Vvesti spisok" << endl;
cout << "4. Open file" << endl;
cout << "5. Vivesti result" << endl;
cout << "6. Vivesti v fail" << endl;
cout << "7. Kluch" << endl;
cout << "8. Exit" << endl;
int i;
cin >> i;
cout << endl;
return i;
}
void nnf()
{
cout << "Vvedite file name" << endl;
cin >> name;
}
void newf()
{
if ((fl = fopen(name,"wb"))==NULL){
cout << "Oshibka pri sozdanii"<<endl;
exit(1);
}
cout << "OK" << endl;
fclose(fl);
}
void spisok()
{
cout << "Vvedite chislo detalei " << endl;
cin >> nst;
for (int i=0; i<nst; i++) {
cout << "Vvedite kod: ";
cin >> det[i].kod;
cout << "Vvedite kolichestvo: ";
cin >> det[i].kol;
cout << "Vvedite mesyac: ";
cin >> det[i].mes;
fwrite( &det[i], sizeof(detail), 1, fl );
cout << endl;
}
cout << "mesn: "; cin >> mesn;
{
k=mesn-1;
for(int i=0;i<k;i++)
cout << det[i].mes <<"mesyac "<< det[i].kod <<"kod "<< det[i].kol <<"kol "<< endl;}
fclose(fl);
}
void opf()
{
if ((fl = fopen(name,"rb"))==NULL) {
cout << "Oshibka pri otkritii"<<endl;
exit(1);
}
nst=0; detail std;
while(true) {
int nwrt = fread( &std, sizeof(detail), 1, fl );
if (nwrt!=1) break;
det[nst]=std;
cout << det[nst].kod << " " << det[nst].kol<< " " << det[nst].mes<< endl;
nst++;
}
fclose(fl);
}
void resc()
{
for (int i=0; i<mesn; i++)
if (det[i].mes==mesn) {cout << det[i].mes << det[i].kod << det[i].kol << endl;
}
}
void vyb(detail det[] , int n)
{
int imin,i,j;
detail t;
for(i=0; i<n-1; i++) {
imin=i;
for(j=i+1; j<n; j++)
if (det[imin].mes>det[j].mes) imin=j;
if (imin != i) {
t = det[imin];
det[imin] = det[i];
det[i] = t; }
}
for (int i=0; i<nst; i++) {
cout << det[i].mes <<"mesyac "<< det[i].kod <<"kod "<< det[i].kol <<"kol "<< endl;
if (det[i].kod==1)
cout << "kod detali " << det[i].kol <<endl;
if (det[i].kod==2)
cout << "kod detali" << det[i].kol <<endl;
}
}
void resf()
{
char namet[30];
FILE *ft;
cout << "Vvedite imya faila" << endl;
cin >> namet;
if ((ft = fopen(namet,"w"))==NULL){
cout << "Oshibka pri sozdanii "<<endl;
exit(1);
}
fclose(ft);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question