Jump to content



Photo

Newbie C++ Help


  • Please log in to reply
211 replies to this topic

#166 serverul

serverul

    alecs

  • Joined: 01-November 05

Posted 23 May 2008 - 19:10

main file
[codebox]
#include "student.cpp"

int main() {

Student *alin = new Student("Alin", "Bata", "1870513350037", 2008, 6, 3, 5, 8, 4, 9);

alin->studentPrint();

ofstream store ("studenti.txt");
if (store.is_open()) {
store << alin->getNume() << alin->getPrenume() << alin->getMediaGenerala() <<
alin->getCrediteObtinute() << endl;
}
else cout << "Unable to open file" << endl;
store.close();

return 0;
}
[/codebox]

student.cpp file

[codebox]
#include <iostream>
#include <fstream>

#include "student.h"

using namespace std;

//constructors
Student::Student() {
this->nume = "";
this->prenume = "";
this->cnp = "";
this->promotia = 0;
this->grupa = 0;
this->notaAnalizaMatematica = 0;
this->notaProgramareC = 0;
this->notaAlgoritmica = 0;
this->notaBazeleInformaticii = 0;
this->notaEngleza = 0;
this->mediaGenerala = 0;
this->crediteObtinute = 0;
};

int calculcredite(double notaAnalizaMatematica, double notaProgramareC, double notaAlgoritmica,
double notaBazeleInformaticii, double notaEngleza);

Student::Student(string nume, string prenume, string cnp, int promotia, int grupa,
double notaAnalizaMatematica, double notaProgramareC, double notaAlgoritmica,
double notaBazeleInformaticii, double notaEngleza) {
this->nume = nume;
this->prenume = prenume;
this->cnp = cnp;
this->promotia = promotia;
this->grupa = grupa;
this->notaAnalizaMatematica = notaAnalizaMatematica;
this->notaProgramareC = notaProgramareC;
this->notaAlgoritmica = notaAlgoritmica;
this->notaBazeleInformaticii = notaBazeleInformaticii;
this->notaEngleza = notaEngleza;
this->mediaGenerala = ((notaAnalizaMatematica + notaProgramareC
+ notaAlgoritmica + notaBazeleInformaticii + notaEngleza) / 5);
this->crediteObtinute = calculcredite(notaAnalizaMatematica,
notaProgramareC, notaAlgoritmica, notaBazeleInformaticii, notaEngleza);
};

int calculcredite(double notaAnalizaMatematica, double notaProgramareC,
double notaAlgoritmica, double notaBazeleInformaticii, double notaEngleza) {
int temp = 0;
if(notaAnalizaMatematica >= 5) {
temp = temp + 6;
}
if(notaProgramareC >= 5) {
temp = temp + 6;
}
if(notaAlgoritmica >= 5) {
temp = temp + 6;
}
if(notaBazeleInformaticii >= 5) {
temp = temp + 6;
}
if(notaEngleza >= 5) {
temp = temp + 6;
}
return temp;
};

//deconstructors

//get functions
double Student::getMediaGenerala(void) {
return this->mediaGenerala;
};
int Student::getCrediteObtinute(void) {
return this->crediteObtinute;
};
string Student::getNume(void) {
return this->nume;
};
string Student::getPrenume(void) {
return this->prenume;
};

//print class
void Student::studentPrint(void) {
cout << this->nume << this->prenume << this->cnp << this->promotia << this->grupa <<
this->notaAnalizaMatematica << this->notaProgramareC << this->notaProgramareC <<
this->notaAlgoritmica << this->notaBazeleInformaticii << this->notaEngleza <<
this->mediaGenerala << this->crediteObtinute << endl;
};
[/codebox]

student.h file //here is the class declared

[codebox]#include <string>

using namespace std;

class Student {
public:
Student();
Student(string nume, string prenume, string cnp, int promotia, int grupa, double notaAnalizaMatematica,
double notaProgramareC, double notaAlgoritmica, double notaBazeleInformaticii, double notaEngleza);
~Student();
//get functions
string getNume(void);
string getPrenume(void);
double getMediaGenerala(void);
int getCrediteObtinute(void);
//print function
void studentPrint(void);
private:
string nume;
string prenume;
string cnp;
int promotia;
int grupa;
double notaAnalizaMatematica;
double notaProgramareC;
double notaAlgoritmica;
double notaBazeleInformaticii;
double notaEngleza;
double mediaGenerala;
int crediteObtinute;
};
[/codebox]

ty


#167 Internet

Internet

    Neowinian

  • Joined: 03-December 07

Posted 23 May 2008 - 19:53

why did you double the same variable twice? :s

#168 serverul

serverul

    alecs

  • Joined: 01-November 05

Posted 23 May 2008 - 21:01

why did you double the same variable twice? :s



mhh of what variable are you refering?

#169 serverul

serverul

    alecs

  • Joined: 01-November 05

Posted 24 May 2008 - 14:51

problem solved, I included 1 file twice by mistake :(

ty Internet for help :)

#170 Electric Jolt

Electric Jolt

    Lucid Dreamer

  • Joined: 23-July 07
  • Location: United States

Posted 16 January 2009 - 22:32

At first, I didn't really though many people would reply, Thanks. First, I think I am going to get started with C then move on to C++ and maybe create my first program(thinking too far ahead). Oh yeah, I am also 13 and I figure this is the best time to learn since I am yuong and I will get materials better. Again, Thanks for everything.



Ok shouldn't you try learning Visual Basic first? I tryed learning other languages first like WPF and stuff like that, it never worked out for me because Visual Basic is the beginning for programming. I never understood how programming worked, until I learned a little Visual Basic, which would help you learn the next programming language. Well I know this post is old, but it also is still valid for asking this question.

#171 HexFlash

HexFlash

    Neowinian

  • Joined: 04-March 09

Posted 05 March 2009 - 03:09

I've found that you can't go wrong with a copy of C++ for Dummies and a Dev-C++ compiler.

#172 vks87

vks87

    Neowinian

  • Joined: 24-March 09

Posted 24 March 2009 - 06:55

Have a look on this link..:
www.cplusplus.com/doc/tutorial/

Its really a best tutorial and with example of codes so go ahead man..Good luck..

#173 ViZioN

ViZioN

    Resident Scotsman

  • Joined: 17-January 05
  • Location: Edinburgh

Posted 25 March 2009 - 21:03

Have a look on this link..:
www.cplusplus.com/doc/tutorial/

Its really a best tutorial and with example of codes so go ahead man..Good luck..


It's a great group of tutorials :)

#174 nonick

nonick

    Neowinian

  • Joined: 04-May 02

Posted 25 March 2009 - 21:07

I know I'm a little (very) late in this thread, but...

C++ is old! move to Java! it's much much better!


And better yet, focus on internet technologies, PHP or JSP or JSF and AJAX/CSS/XHTML

It's more fun than the old boring languages!

w3schools.com one of the best sources for most of them!

Edited by nonick, 25 March 2009 - 21:12.


#175 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 12
  • Joined: 26-October 05

Posted 25 March 2009 - 22:15

C++ is old! move to Java! it's much much better!

Java is so 1995. It's about time we moved on to C#. Wait, C# is so 2001... :p

#176 vetCalum

Calum

    Neowinian Senior

  • Joined: 10-January 07

Posted 29 March 2009 - 13:20

Java is so 1995. It's about time we moved on to C#. Wait, C# is so 2001... :p

Not C# 3.0 :p

#177 vks87

vks87

    Neowinian

  • Joined: 24-March 09

Posted 31 March 2009 - 11:43

1. Bloodshed is more c++ standards compliant than VC++ 6.0 because VC++ predates the standards.

2. VC++ has better IDE and debugging facilities, produces tighter optimized code, and compiles MFC.

#178 JonathanVP

JonathanVP

    Neowinian Senior

  • Joined: 08-October 03
  • Location: Hicktown Hell Hole

Posted 31 March 2009 - 11:44

Ok, I got inspired today to learn a programing language. I want to learn C++ but I am sitting here with no clue on earth on where to start. Can anyone give me links to newbie tutorials and sites? If you can, please state any tips that you have for me, thanks!


errr...Google..seriously VS 2008 Express is free and you can download to learn C++.

#179 cammy

cammy

    Neowinian

  • Joined: 14-December 05

Posted 31 May 2009 - 19:09

Hey guys, i need some BIG help.

Its the last 2 weeks of my computing course at college and i am panicking over my program, the tutor isn't allowed to help me with the program all he can do is say whether its wrong or right and what i need to do next etc.

Anyways, i have the program half done at least, but now i am completely stumped, i was wondering if someone here could add me on msn and help me finish the program, i wouldn't bother asking but i suck at it and its not my strong side not to mention its a required credit to pass HNC computing!

#180 Jexel

Jexel

    Enth E Nd I 1

  • Joined: 12-June 04
  • Location: Sydney

Posted 04 June 2009 - 12:25

Hey guys, i need some BIG help.

Its the last 2 weeks of my computing course at college and i am panicking over my program, the tutor isn't allowed to help me with the program all he can do is say whether its wrong or right and what i need to do next etc.

Anyways, i have the program half done at least, but now i am completely stumped, i was wondering if someone here could add me on msn and help me finish the program, i wouldn't bother asking but i suck at it and its not my strong side not to mention its a required credit to pass HNC computing!


If you have a programming problem, post that. Stackoverflow.com is always a great place to ask for help. If you need somebody to actually FINISH your assignment then that's just your own laziness.