Apr 15, 2009 at 10:37am UTC
string sigla(string nome)
{
string a = "Ola ";
string b = "mundo!";
stringstream ss;
ss << a << 278627;
string c = ss.str();
string r = "";
if (nome.size() > 0)
r += nome[0];
for (int i = 0; i < nome.size(); i++)
{
if (nome[i] == ' ')
{
r += nome[i + 1];
i++;
}
}
return r;
}
Apr 15, 2009 at 10:38am UTC
class Nome {
public:
char primnom[128];
char ultnom[128];
int cc;
};
#define const MAX=25;
bool getdat(Nome & non)
{
cout<<"qual o nome?"<<endl;
cin>>non.primnom;
cout<<"qual o ultimo?"<<endl;
cin>>non.ultnom;
cout<<"qual o cc?"<<endl;
cin>>non.cc;
return true;
}
void displayNom(Nome & non)
{
cout<<non.primnom<<non.ultnom<<non.cc<<endl;
}
main(){
Nome non[MAX] //estou a instanciar o nome com 25 posiçoes p escrever
int i, j;
cout<<"Introduza o seu nome e o numero d cartao d credito"<<endl;
while(getdata(non[i] && i<MAX)
{i++;
}
for(j=0; j<i; j++)
{
displayNom(non[i]);
}
/*estou a usar um char em vez d um string */
>as classes podem ter funçoes la dentro ^-^
funçao numa classe
class student {
float addgrade (int hours, float grade);
}
student::addgrade(int hours, float grade);
para imprimir funçoes d uma classe
cout<<a1.getnome()<<endl;
Apr 15, 2009 at 10:39am UTC
class Turma {
private:
string curso;
int numero;
int ano;
int capacidade;
public:
Turma(string curs, int num, int an, int cap) {
curso=curs;
numero=num;
ano=an;
cap=capacidade=20; }
void setcurso(string curs) {
curso=curs; }
string getcurso() { return curso; }
void setnumer(int num) {numero=num;}
int getnumer() {return numero;}
void setano(int an) {ano=an;}
int getano() {return ano;}
void setcapac(int capa) {capacidade=capa;}
int getcapa() {return capacidade;}
Apr 15, 2009 at 10:46am UTC
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
int procurarAluno(string sigla, char *turma)
{
string c,a, k;
ifstream ak;
int i=1;
ak.open(turma);
if(ak.is_open()) {
getline(ak,k,'\n');
istringstream iss(sigla, istringstream::in);
while(!iss.eof()) {
iss>>c;
a.push_back(c[0]);
c.clear();
i++;}
if(sigla.compare(a)==0)
{
return i;
ak.close();
}
else {return 0;}
ak.close();
}
}
void lerTurma(char *turma)
{
ifstream ab(turma);
char nome[20];
ab.open(turma);
if(ab.is_open())
{
while(ab.getline(nome, 20)){
cout<<nome<<endl;
}
}
ab.close();
}
int numAl(char *turma)
{
int a;
string s;
ifstream ab;
ab.open(turma);
while(getline(ab, s, '\n'))
{a++;}
ab.close();
return a;
}
int inscreverAluno(char *turma)
{
string b;
int i=0;
ofstream ac;
ac.open(turma);
cout<<"introduza o nome"<<endl;
getline(cin, b);
ac<<b<<endl;
ac.close();
return i;
}
int main(int argc, char* argv[])
{
char *turma="turma.txt";
ifstream turm;
int b=0, i, h, a,k, u;
string s;
turm.open(turma);
if(turm.is_open())
{
cout<<"deseja inscrever um aluno? "<<endl;
while(!turm.eof() && b<20)
{
inscreverAluno(turma);
b++;}
cout<<"deseja consultar a turma?"<<endl;
lerTurma(turma);
cout<<"deseja procura pela sigla?"<<endl;
cout<<"insira a sigla"<<endl;
getline(cin, s);
cout<<procurarAluno(s, turma);
}
return 0;}
Apr 15, 2009 at 10:48am UTC
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <strings.h>
using namespace std;
void escre(char *saida, int alt, int larg)
{
ofstream file(saida, ios::app);
file << "altura:" << larg << " largura:" << alt << endl;
file.close();
}
void girar(int alt, int larg)
{
int j=0;
j=alt;
alt=larg;
larg=j;
}
int area(int alt, int larg)
{
int a;
a=alt*larg;
return a;
}
int main(int argc, char* argv[])
{
ifstream a;
char *b=argv[2];
string s;
int alt, larg, k, l;
a.open(argv[1]);
if(a.is_open()) {
while(!a.eof())
{
getline(a, s, ':');
a>>alt;
getline(a,s,':');
a>>larg;
cout<<" esta eh a altura\n"<<alt<<endl;
cout<<" esta eh a largura\n"<<larg<<endl;
cout<<" esta eh a area\n"<<area(alt, larg);
}
a.close();}
cout<<"\ngirar 90 graus"<<endl;
cout<<"insira a altura"<<endl;
cin>>k;
cout<<"insira a largura"<<endl;
cin>>l;
girar(k,l);
cout<<"a nova altura "<<l<<endl;
cout<<"a nova largura"<<k<<endl;
escre(b, k, l);
return 0;}
Apr 15, 2009 at 10:51am UTC
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
ofstream a;
int b=0;
a.open(argv[1]);
if(a.is_open())
{
while(!a.eof())
{
cout<<"introduza o seu b"<<endl;
cin>>b;
a<<b;
a<<endl;
}
}
a.close();
return 0;}
Apr 15, 2009 at 10:53am UTC
if(k.compare("max")==0)
{res=max(val, o);}
Apr 15, 2009 at 12:08pm UTC
public:
//construtor
Animal(string, bool, char *, int);
Animal(string, bool, char *, int, Veterinario);
Animal(Animal &);
~Animal(); //destrutor
Apr 15, 2009 at 1:09pm UTC
Yay! Lets all keep posting and get our post count up... whats going on with the beginners board and all these posts I can't understand :(
Apr 15, 2009 at 2:10pm UTC
make :
all:
f5e1
animal.o: animal.cpp animal.h
g++ animal.cpp -o animal.o
f5e1: animal.o
g++ animal.o -Wall -c animal
____________
constructores e destructores e stuff
class Animal{
string nome;
int idade;
bool operator<(const Animal &a);
};
OVERLOAD DE OPERADORES
bool& Animal::operator<(const Animal& a)
{
return idade < a.idade;
}
Animal& Animal::operator=(const Animal &a){
nome = a.nome;
return *this;
}
ostream Animal::operator<< (ostream o, Animal &a){
o << nome << "\t" << "ola " << idade << endl;
return o;
}
Animal a1, a2;
if(a1 < a2)
cout << "sim sr\n";
void Animal::setNome(string nom){
nome = nom;
}
a1.<(a2)
a1.func(a2)
a1 = a2;
int a = 0;
int b;
b = a;
int func(){
}
int func(int a){
}
Animal::Animal(string nom) : nome(nom), idade(id){
}
int main(){
Animal a1;
string nome = "paulo";
a1.setNome(nome);
cout << a1;
file << a1;
file >> a;
int a;
cIn
cOut
Ifstream
Ofstream
file >> a;
getline(file, s, '\n')
}
Last edited on Apr 15, 2009 at 2:10pm UTC
Apr 15, 2009 at 2:12pm UTC
As far I do know, they're doing a test or something similar... Also, you can translate it to english using Google Translate. That language is Portuguese.