Click here to Skip to main content
15,886,519 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem creating an array of "class" Pin
Roberto64_Ge8-Sep-22 5:27
Roberto64_Ge8-Sep-22 5:27 
GeneralRe: Problem creating an array of "class" Pin
Richard MacCutchan8-Sep-22 5:17
mveRichard MacCutchan8-Sep-22 5:17 
GeneralRe: Problem creating an array of "class" Pin
Roberto64_Ge8-Sep-22 5:26
Roberto64_Ge8-Sep-22 5:26 
GeneralRe: Problem creating an array of "class" Pin
Richard MacCutchan8-Sep-22 5:38
mveRichard MacCutchan8-Sep-22 5:38 
GeneralRe: Problem creating an array of "class" Pin
Roberto64_Ge8-Sep-22 5:43
Roberto64_Ge8-Sep-22 5:43 
GeneralRe: Problem creating an array of "class" Pin
Roberto64_Ge8-Sep-22 5:37
Roberto64_Ge8-Sep-22 5:37 
GeneralRe: Problem creating an array of "class" Pin
Richard MacCutchan8-Sep-22 5:45
mveRichard MacCutchan8-Sep-22 5:45 
GeneralRe: Problem creating an array of "class" Pin
Roberto64_Ge8-Sep-22 8:04
Roberto64_Ge8-Sep-22 8:04 
header

C++
#include<iostream>
#include<string>
using namespace std;

 class anagrafica
 {
   private:
   
   string nome_cifrato;  
   string cognome_cifrato;   
   int chiave_cifratura;
   
   public : 
   
   anagrafica(string ="", string ="", int=0); //costruttore
   
   void setNome(string );
   
   void setCognome(string );
   
   string getNome();
   
   string getCognome();
   
   void codifica(string , string , int );
   
   void decodifica();
   
   void setChiave(int);
    
   int getChiave();
   
   void stampa();
   
   
 };


methods

C++
#include "Anagrafica.h"
#include <iostream>
#include <string>

using namespace std;



anagrafica::anagrafica(string name,string surname, int key)
{
 nome_cifrato=name;
 cognome_cifrato=surname;
 chiave_cifratura=key;
}

void anagrafica::setNome(string n_)
   {
   nome_cifrato=n_;
   }
void anagrafica::setCognome(string c_)
   {
   cognome_cifrato=c_;
   }

   
string anagrafica::getNome()
   {
   return nome_cifrato;
   }
string anagrafica::getCognome()
   {
   return cognome_cifrato;
   }

int anagrafica::getChiave()
{
 return chiave_cifratura;
 }

void anagrafica::setChiave(int c)
{
 chiave_cifratura=c;
}

void anagrafica::stampa()
{
    string nom = nome_cifrato;
    string cog = cognome_cifrato;
 cout<<" nome  cifrato "<<nom;
 cout<<" cognome  cifrato "<<cog<<endl;
}


void anagrafica::codifica(string nome_chiaro, string cognome_chiaro, int chiave)
{ 
 char car;
 nome_cifrato = "";
 cognome_cifrato = "";
 for (int i=0;i <nome_chiaro.length();i++)
    {
     car = nome_chiaro[i] + chiave;
     nome_cifrato = nome_cifrato + car;
     cout<<"carattere "<<i<<" n in chiaro "<<nome_chiaro[i]<<" chiave  "<<chiave<<" cifrato "<<car<<" nome incostruzione "<<nome_cifrato<<endl;
    }
 setNome(nome_cifrato);     
 for (int i=0; i<cognome_chiaro.length();i++)
    {
     car = cognome_chiaro[i] + chiave;
     cognome_cifrato = cognome_cifrato + car;
     cout<<"carattere "<<i<<" c in chiaro "<<cognome_chiaro[i]<<" chiave  "<<chiave<<" cifrato "<<car<<" cognome incostruzione "<<cognome_cifrato<<endl;
    }
 setCognome(cognome_cifrato);   
}
   
void anagrafica::decodifica()
{ 

 char car;
 string nome_chiaro = "";
 string cognome_chiaro = "";
 for (int i=0;i <nome_cifrato.length();i++)
    {
     car = nome_cifrato[i] - chiave_cifratura;
     nome_chiaro = nome_chiaro + car;
     cout<<"carattere "<<i<<" n in cifrato "<<nome_cifrato[i]<<" chiave  "<<chiave_cifratura<<" chiaro "<<car<<" nome incostruzione "<<nome_chiaro<<endl;
    }
 cout<<" nome in chiaro "<<nome_chiaro;     
 for (int i=0; i<cognome_cifrato.length();i++)
    {
     car = cognome_cifrato[i] - chiave_cifratura;
     cognome_chiaro = cognome_chiaro + car;
     cout<<"carattere "<<i<<" c in cifrato "<<cognome_cifrato[i]<<" chiave  "<<chiave_cifratura<<" chiaro "<<car<<" cognome incostruzione "<<cognome_chiaro<<endl;
    }
 cout<<" cognome in chiaro "<<cognome_chiaro<<endl; 
}


main

C++
#include "Anagrafica.h"
#include <iostream>
#include <fstream>
#include <string>


using namespace std;


 
void cod (anagrafica arr,string n, string c,int chiave)
{

arr.codifica(n,c,chiave); 

}
 
 
void decod (anagrafica arr)
{

arr.decodifica(); 

}
 
int main()
{
ifstream file; // dichiarazione del file
file.open("input.txt"); //apertura del file

int N;
string n,c;

int chiave;
int chiave_input;

file>>N; //legge il primo numero
cout<<N<<endl;

anagrafica* Arr_ = new anagrafica[N];
// this is only for test
for (int i = 0; i < N; i++)
{
	Arr_[i] = anagrafica("ciao", "miao", i*25);
}
for (int i=0; i<N; i++)
{
 file>>chiave;
 file>>n;
 file>>c;
 Arr_[i].setChiave(chiave);
 cod(Arr_[i],n,c,chiave);
}
for (int i=0; i<N; i++)
	Arr_[i].stampa();

cout<<"inserire un valore intero"<<endl;
cin>>chiave_input;

for (int i=0; i<N; i++)
{
 cout<<" chiave  "<< Arr_[i].getChiave()<<endl;
 if(chiave_input== Arr_[i].getChiave())
 decod(Arr_[i]);
}
 
}


That's it.
Highlighted, within method "codifica", the call to the two methods setNome and setCognome that do not work (they do not set any name and surname). The two cout inside "codifica" are only to understand what happens.


The txt file from where to take the data to process is made like this

2 (means how many rows follows)
key1 name1 surname1
key2 name2 surname2
GeneralRe: Problem creating an array of "class" Pin
Richard MacCutchan8-Sep-22 23:37
mveRichard MacCutchan8-Sep-22 23:37 
GeneralRe: Problem creating an array of "class" Pin
Roberto64_Ge9-Sep-22 10:30
Roberto64_Ge9-Sep-22 10:30 
GeneralRe: Problem creating an array of "class" Pin
Richard MacCutchan9-Sep-22 22:00
mveRichard MacCutchan9-Sep-22 22:00 
GeneralRe: Problem creating an array of "class" Pin
Roberto64_Ge10-Sep-22 0:34
Roberto64_Ge10-Sep-22 0:34 
GeneralRe: Problem creating an array of "class" Pin
Richard MacCutchan10-Sep-22 0:47
mveRichard MacCutchan10-Sep-22 0:47 
QuestionHow can do it in c++? Pin
Member 157580955-Sep-22 6:07
Member 157580955-Sep-22 6:07 
GeneralRe: How can do it in c++? Pin
Richard MacCutchan5-Sep-22 6:43
mveRichard MacCutchan5-Sep-22 6:43 
AnswerRe: How can do it in c++? Pin
Greg Utas5-Sep-22 6:44
professionalGreg Utas5-Sep-22 6:44 
QuestionRe: How can do it in c++? Pin
CPallini5-Sep-22 20:50
mveCPallini5-Sep-22 20:50 
QuestionMessage Closed Pin
4-Sep-22 5:28
Member 149687714-Sep-22 5:28 
AnswerRe: Combining QProcess, qterminal and bluetoothctl...in C++ code Pin
Mircea Neacsu4-Sep-22 6:05
Mircea Neacsu4-Sep-22 6:05 
GeneralMessage Closed Pin
4-Sep-22 6:38
Member 149687714-Sep-22 6:38 
GeneralRe: Combining QProcess, qterminal and bluetoothctl...in C++ code PinPopular
Gerry Schmitz4-Sep-22 8:21
mveGerry Schmitz4-Sep-22 8:21 
AnswerRe: Combining QProcess, qterminal and bluetoothctl...in C++ code Pin
Richard MacCutchan4-Sep-22 21:37
mveRichard MacCutchan4-Sep-22 21:37 
QuestionMessage Closed Pin
29-Aug-22 7:23
Member 1496877129-Aug-22 7:23 
AnswerRe: foreach - basic C++ question Pin
Victor Nijegorodov29-Aug-22 7:40
Victor Nijegorodov29-Aug-22 7:40 
AnswerRe: foreach - basic C++ question Pin
Maximilien29-Aug-22 8:23
Maximilien29-Aug-22 8:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.