Results 1 to 11 of 11

Thread: C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Dec:2020
    Location:
    Posts: 3

    C++

    ,
    ++, , , :
    , , ;

    , , " ".

    , , , .

    .


    --------------------------------

    - . :
     , ;
     1 , ;
     2 ;
     3 , , ;
     4 ;




    -------------------------------

    #include <iostream>
    #include <fstream>

    using namespace std;

    string nameGame;
    int genreGame,processor,ram,numAvailable;
    char multiplayer;
    double price;

    int main()
    {
    cout << "Please, choose your function: " << endl;

    cout << " [1] Create a new file and add product details." << endl;
    cout << " [2] Open an existing file." << endl;
    // cout << " [3] " << endl;
    cout << " [4] Add new record." << endl;

    cout << "\n Number of function: ";
    short nSign;
    cin >> nSign;

    switch( nSign ){
    {
    case 1:
    cout << " Function 'Create a new file with product details': " << endl;

    string sFileName;
    cout << "\n Enter a file name: ";
    cin >> sFileName;
    sFileName += ".txt";

    ofstream newFile;
    newFile.open( sFileName.c_str() );

    cout << " Enter details: ";

    for(int k = 0; k < 7; k++){
    string line;
    cin >> line,
    newFile << line + " ";
    }
    newFile.close();



    break;
    }

    {
    case 2:
    cout << " Function 'Open an existing file': " << endl;
    cout << "\n Enter the full file name: ";

    string line;
    cin >> line;
    ifstream myfile (line);

    if (myfile.is_open()){

    while ( getline (myfile,line) ){

    cout << "\n " + line << '\n';
    }

    myfile.close();
    }

    else cout << "Unable to open file";

    break;
    }

    {
    case 4:
    ofstream outfile;

    outfile.open("input.txt",ios_base::app);

    if(!outfile){
    cout << "Error Opening File" << endl;
    return -1;
    } else {

    for(int k = 0; k < 7; k++){
    string line;
    cin >> line,
    outfile << line + " ";
    }
    outfile.close();
    }



    break;
    }

    default:
    cout << "\nFunction "" << nSign << "" does not exist." << endl;
    break;
    }

    return 0;
    }

  2. #2
    Registered User BeTaTesTeR's Avatar
    Join Date: Nov:2006
    Location:
    Posts: 6,693
    .1, .3 .1 .3. .
    !

  3. #3
    Registered User QuadCore's Avatar
    Join Date: Oct:2007
    Location: Sofia
    Posts: 1,216
    Quote Originally Posted by BeTaTesTeR View Post
    .1, .3 .1 .3. .
    2. - :

    0 : | | ... ( )
    1: Call of Duty | FPS | Yes ....
    2: League of Legends | MOBA | Yes ...
    ....

    : ( , ), .
    Last edited by QuadCore; 11th December 2020 at 09:50.

  4. #4
    Registered User
    Join Date: Jan:2010
    Location: localhost:502
    Posts: 153
    CSV (- !) -
    Cyrix 486DLC@33MHz,WD 80MB Caviar,8MB RAM,SVGA ISA,Tatung14"mono

  5. #5
    Registered User lindroos1's Avatar
    Join Date: Feb:2015
    Location: --
    Posts: 1,101
    , , .1 - 7 "", . .
    .3 - "" , .
    Last edited by lindroos1; 11th December 2020 at 12:39. Reason: .
    Those who abjure violence can only do so because others are committing violence on their behalf. - Orwell

  6. #6
    Registered User QuadCore's Avatar
    Join Date: Oct:2007
    Location: Sofia
    Posts: 1,216
    Quote Originally Posted by lindroos1 View Post
    , , .1 - 7 "", . .
    .3 - "" , .
    , -

  7. #7
    Registered User
    Join Date: Dec:2020
    Location:
    Posts: 3
    2. - :

    0 : | | ... ( )
    1: Call of Duty | FPS | Yes ....
    2: League of Legends | MOBA | Yes ...
    ....

    : ( , ), .

    -----------------------------


    , , .
    .
    .

    - - - - - -

    .

    - - - - - -

    Quote Originally Posted by lindroos1 View Post
    , , .1 - 7 "", . .
    .3 - "" , .
    -------------------

    7 "" , 3.

    :

    , :
    ();
    ( , );
    ( GHz|);
    RAM ( );
    (Y/N);
    ();
    .

    1.
    2. .
    3. ( ) - ( - ).


    -------------------------
    .
    Last edited by KristinaDim; 11th December 2020 at 16:51.

  8. #8
    Registered User lindroos1's Avatar
    Join Date: Feb:2015
    Location: --
    Posts: 1,101
    , . , .
    Those who abjure violence can only do so because others are committing violence on their behalf. - Orwell

  9. #9
    Registered User mitkohr's Avatar
    Join Date: Jul:2001
    Posts: 1,361
    , , ++, .
    .1, .2, 4 , .3 .

    Code:
    //GamesDB.h
    #pragma once
    #include <string>
    #include <iostream>
    #include <sstream>
    
    using namespace std;
    
    class Games
    {
    
    public:
    	std::string name;
    	std::string genre;
    	double cpuFreq;
    	double ram;
    	bool multi;
    	int available;
    	double price;
    
    	Games(std::string name_ = "", std::string genre_ = "", double cpuFreq_ = 0.0, double ram_ = 0.0, bool multi_ = false, int available_ = 0, double price_ = 0.0)
    		:name(name_), genre(genre_), cpuFreq(cpuFreq_), ram(ram_), multi(multi_), available(available_), price(price_) {};
    	~Games() {};
    
    	std::string getName();
    	std::string getGenre();
    	double getCpuFreq();
    	double getRam();
    	bool getMulti();
    	int getAvailable();
    	double getPrice();
    
    	string makeLine();
    
    	friend istream& operator>>(istream& in, Games& data);
    	friend ostream& operator<<(ostream& out, Games& data);
    };
    Code:
    //GamesDB.cpp
    #include "GamesDB.h"
    
    
    std::string Games::getName() {
    	return name;
    }
    std::string Games::getGenre() {
    	return genre;
    }
    double Games::getCpuFreq() {
    	return cpuFreq;
    }
    double Games::getRam() {
    	return ram;
    }
    bool Games::getMulti() {
    	return multi;
    }
    int Games::getAvailable() {
    	return available;
    }
    double Games::getPrice() {
    	return price;
    }
    
    istream& operator>>(istream& in, Games& data) {
    	in.read((char*)&data.name, sizeof(data.name));
    	in.read((char*)&data.genre, sizeof(data.genre));
    	in.read((char*)&data.cpuFreq, sizeof(data.cpuFreq));
    	in.read((char*)&data.ram, sizeof(data.ram));
    	in.read((char*)&data.multi, sizeof(data.multi));
    	in.read((char*)&data.available, sizeof(data.available));
    	in.read((char*)&data.price, sizeof(data.price));
    	return in;
    }
    
    ostream& operator<<(ostream& out, Games& data) {
    	out.write((char*)&data.name, sizeof(data.name));
    	out.write((char*)&data.genre, sizeof(data.genre));
    	out.write((char*)&data.cpuFreq, sizeof(data.cpuFreq));
    	out.write((char*)&data.ram, sizeof(data.ram));
    	out.write((char*)&data.multi, sizeof(data.multi));
    	out.write((char*)&data.available, sizeof(data.available));
    	out.write((char*)&data.price, sizeof(data.price));
    	return out;
    }
    
    string Games::makeLine() {
    	stringstream sstr;
    	sstr << boolalpha << fixed << name << " " << genre << " " << cpuFreq << " " << ram << " " << multi << " " << available << " " << price;
    	return sstr.str();
    }
    Code:
    // GamesDBDB .h
    #include <map>
    #include "GamesDB.h"
    
    using namespace std;
    
    class GamesDBDB {
    private:
    	map<string, Games> items;
    public:
    	GamesDBDB() {};
    	~GamesDBDB() { items.clear(); };
    	void add(Games item) {
    		items.insert(make_pair(item.getName(), item));
    	}
    	friend istream& operator>>(istream& in, GamesDBDB& data);
    	friend ostream& operator<<(ostream& out, GamesDBDB& data);
    
    	void print(ostream& out);
    };
    Code:
    //GamesDBDB.cpp
    #include "GamesDBDB.h"
    
    istream& operator>>(istream& in, GamesDBDB& data) {
    	Games item;
    	while (in >> item) {
    		data.add(item);
    	}
    	return in;
    }
    
    ostream& operator<<(ostream& out, GamesDBDB& data) {
    	for (map<string, Games>::iterator it = data.items.begin(); it != data.items.end(); ++it) {
    		out << it->second;
    	}
    	return out;
    }
    
    void GamesDBDB::print(ostream& out) {
    	for (map<string, Games>::iterator it = items.begin(); it != items.end(); ++it) {
    		out << it->second.makeLine() << endl;
    	}
    }
    Code:
    //Main.cpp
    #include "GamesDB.h"
    #include "GamesDBDB.h"
    #include <fstream>
    
    
    int main() {
    	GamesDBDB db;
    	db.add(Games("a", "b", 3.0, 8.0, false, 12, 10.0));
    	db.add(Games("c", "d", 4.0, 9.0, true, 20, 30.0));
    	db.print(cout);
    	cout << "============================" << endl;
    	std::ofstream f("c:\\temp\\data.txt");
    	f << db;
    	f.close();
    	cout << "============================" << endl;
    	GamesDBDB db2;
    	std::ifstream f2("c:\\temp\\data.txt");
    	f2 >> db2;
    	f2.close();
    	db2.print(cout);
    	cout << "============================" << endl;
    	char c;
    	cin >> c;
    }
    /Hidden:

    :
    string makeLine();// .2
    friend istream& operator>>(istream& in, Games& data); //.1,.4
    friend ostream& operator<<(ostream& out, Games& data);// .3

    map, .
    Last edited by mitkohr; 16th December 2020 at 13:23.
    Gigabyte X570 Aorus Elite, AMD Ryzen 7 5800X@PBO+200, Noctua NH-D15, 2x16GB G.Skill F4-3600C17D-32GTZR, Palit GeForce RTX 4070 Ti GameRock Classic, 2x Sandisk Extreme II 240GB (not in RAID)+WD 320GB AAKS + WD40EZRZ + Toshiba X300 6GB, Cooler Master HAF 922, CORSAIR 750W CX

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |