Új hozzászólás Aktív témák
-
icespeak
csendes tag
Hellótok C++-ban a header fájlnál van problémám a függvényekkel
#include "read.h"
#include "ellenoriz.h"
#include <iostream>
#include <vector>
#include <sstream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
vector<vector<int> > t;
char ch;
do{
// Adatok beolvasása
vector<vector<int> > t;
bool file_ok = true;
// Adatbevitel módja
int v;
if(argc>1) v = 1;
else{
cout << "Az adatbeolvasás módja:"<< endl
<< " SZÖVEGES FÁJL(1)"<< endl
<< " BILLENTYŰZET (2)"<< endl;
v = Read12("Válasszon: ","Csak 1 vagy 2 közül választhat!");
}
// Beolvasás
string fname;
switch(v)
{
case 1 :
if(argc<=1){
cout << "Adja meg a szöveges fájl nevét: ";
cin >> fname;
}
else fname = argv[1];
file_ok = ReadFromFile(fname, t);
break;
case 2 :
cout << "Adja meg az értékeket!";
ReadFromKeyboard(t);
break;
}
// Kiíratás
if(file_ok)
{
if(minden(t)) cout << "Minden sorban van legalabb egy primszam"<< endl;
else cout << "Nincs minden sorban primszam"<< endl;
cout << endl << "Futtassam újra? (I/N) "; cin >> ch;
}
}while(ch!='n' && ch!='N');
return 0;
}
read.cpp tartalma
#include "read.h"
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
int Read12(const string &msg, const string &errormsg)
{
int n;
bool hiba = true;
do{
cout << msg;
string str;
cin >> str;
n = atoi(str.c_str());
hiba = (n==0 && str!="0") || n<1 || n>2;
if(hiba) cout << errormsg << endl;
}while(hiba);
return n;
}
void ReadFromKeyboard(vector<vector<int> > &t)
{
int n=ReadNat("kerek egy pozitiv egesz szamot( hany soros a matrix):\t","nem pozitiv egesz szamot adtal meg!");
int m=ReadNat("kerek egy pozitiv egesz szamot( hany oszlopa van a matrixnak):\t","nem pozitiv egesz szamot adtal meg!");
t.resize(n);
for (int i=0;i<n;i++)
{
t[i].resize(m);
for (int j=0;j<m;j++)
{
cout <<"t["<<i+1<<"]["<<j+1<<"]: ";
t[i][j]=ReadInt("","nem szamot adtal meg!");
}
}
}
bool ReadFromFile(const string &fname)
{
int n,m,ertek;
int t[n][m];
ifstream x(fname.c_str());
if(x.fail()){
cout << "Hibás fájlnév!"<< endl;
return false;
}
while(!x.eof()){
for (int i=0;i<n;i++)
{
for (int j=0;j<m;j++)
{
x >> ertek;
t[i][j]=ertek;
}
}
}
return true;
}
bool good(int k) {
if (k>0)
{
return true;
}
else
{
return false;
}
}
int ReadInt(string msg, string errormsg, bool cond(int) )
{
int n;
bool hiba;
do{
cout << msg;
string str;
cin >> str;
n = atoi(str.c_str());
hiba = n==0 && str!="0" || !cond(n);
if(hiba) cout<< errormsg<< endl;
}while(hiba);
return n;
}
int ReadNat(string msg, string errormsg, bool cond(int) )
{
int n;
bool hiba;
do{
cout << msg;
string str;
cin >> str;
n = atoi(str.c_str());
hiba = n==0 && str!="0" || n<0 || !cond(n);
if(hiba) cout<< errormsg<< endl;
}while(hiba);
return n;
}
read.h tartalma
#ifndef _READ_
#define _READ_
#include <string>
bool good(int k);
int Read12(const string &msg, const string &errormsg);
void ReadFromKeyboard(vector<vector<int> > &t);
bool ReadFromFile(const string &fname);
int ReadInt(std::string msg, std::string errormsg, bool cond(int) = good);
int ReadNat(std::string msg, std::string errormsg, bool cond(int) = good);
#endif
Új hozzászólás Aktív témák
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- Mint az ÚJ - ÉRINTŐS Lenovo T14 gen5 (Ryzen 5 Pro 8540U) laptop 36 hó GARANCIÁVAL eladó!
- Eladó Brutál B550 Steel Legend alaplap dobozában
- !Akció! Klipsch R-120SW Sub / Mélynyomó
- BMW gyári alufelni, téli gumival
- iPad Air 5th gen (2022) 11" Blue M1 Cellular, ESR Rebound Hybrid Case 360 tok, 5in1 Type-C Hub
- VADIÚJ Bontatlan! Honor 400 Lite 8/256 AMOLED 120Hz Velvet Grey, Dual SIM 2év telekom gar
- GYÖNYÖRŰ iPhone 11 Pro 256GB Midnight Green -1 ÉV GARANCIA - Kártyafüggetlen, MS2048, 96% Akksi
- Lenovo Thinkcentre M920t Tower/ M720s / M920s SFF / i5-8-9. gen/ WIN10-11/számla, garancia
- Asus ROG Zephyrus G15 - 15.6" 4K 120Hz - Ryzen 7 6800HS - 24GB - 512GB - RTX 3060 - 2 hó garancia -
- Telefon felvásárlás!! iPhone 12 Mini/iPhone 12/iPhone 12 Pro/iPhone 12 Pro Max
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: NetGo.hu Kft.
Város: Gödöllő