Ú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!
- Megtartotta Európában a 7500 mAh-t az Oppo
- Fotók, videók mobillal
- Kínai és egyéb olcsó órák topikja
- World of Tanks - MMO
- NBA és kosárlabda topic
- A legújabb iPhone kiegészítő egy zokni, amit magunkra akaszthatunk
- Horgász topik
- Samsung Galaxy A56 - megbízható középszerűség
- Melyik tápegységet vegyem?
- Megérkezett a Google Pixel 7 és 7 Pro
- További aktív témák...
- Lenovo ThinkPad P1 Gen 4 i7 32GB RAM 512GB SSD NVIDIA T1200 16 2560 1600 Garancia
- Dell Precision 7550 i7 32GB RAM 512GB SSD NVIDIA Quadro T1000 FHD
- Dell Precision 5560 i7 32GB RAM 512GB SSD NVIDIA RTX A2000 FHD+
- BOMBA áron eladó új Microsoft Surface Laptop 4 garanciával! AMD Ryzen 5 /16GB 512 SSD/TOUCH/13.5"/
- Dell Latitude 7420 i7 / 32GB /1TB SSD / FHD IPS
- Apple iPhone XR / 128GB / Kártyafüggetlen / 12Hó Garancia / 95% akku
- HIBÁTLAN iPhone 13 Pro 128GB Sierra Blue -1 ÉV GARANCIA - Kártyafüggetlen, MS3667 100% Akkumulátor
- Azonnali készpénzes nVidia RTX 4000 sorozat videokártya felvásárlás személyesen / csomagküldéssel
- Apple iPhone 17 Pro Max 256GB,Uj, Bontatlan,36 hónap garancia
- Samsung Galaxy S24 Ultra 8/256 GB Titanium Gray 6 hónap Garancia Beszámítás Házhozszállítás
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Laptopműhely Bt.
Város: Budapest

