473,763 Members | 1,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with code

7 New Member
there are 3 files but the one iam having problems with is the student.cpp



student.cpp
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>    // for ostream << and istream >>
  2. #include <string> 
  3. #include "student.h"
  4. using namespace std;
  5.  
  6. //--constructors
  7.  
  8. student::student()
  9. {
  10.   my_name = "?name?";
  11.   my_credits = 0.0;
  12.   my_qualityPoints = 0.0;
  13. }
  14.  
  15. student::student(string initName, double initCredits, double initQualityPoints)
  16. {
  17.   my_name = "initName,";
  18.   my_credits = initCredits;
  19.   my_qualityPoints = initQualityPoints;
  20. }
  21.  
  22. //--modifiers
  23.  
  24. void student::completedCourse(double credits, double numericGrade)
  25. {
  26. my_credits = my_credits + credits;
  27. my_qualityPoints = my_qualityPoints + (my_credits * numericGrade);
  28. }
  29.  
  30.  
  31. //--accessors
  32. double student::GPA() const
  33. {
  34.  my_qualityPoints / my_credits;
  35.   return;
  36. }
  37. string student::standing() const
  38. {
  39. if credits > 30 
  40.   return “Freshman”;
  41. if credits >= 30
  42. return “Sophomore”;
  43. if credits >= 60
  44. return “Junior”;
  45. if credits >=90
  46. return “Senior”;
  47.  
  48. }
  49. string student::name() const
  50. {
  51. Return my_name;
  52. }
  53.  
main.cpp
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include "student.h" // this includs student.h
  4. #include "compfun.h"     // for decimals
  5.  
  6. using namespace std;
  7.  
  8. void display(student aStudent)
  9. {
  10.   decimals(cout, 2);
  11.   cout << "{ student: " << aStudent.name();
  12.   cout << ", GPA = " << aStudent.GPA() << " }" << endl;
  13. }
  14.  
  15. int main()
  16. { // test drivbe student: this main will vary a,mongst students
  17.   student aStudent("Nguyen", 36.5, 123.5);
  18.   student anotherStudent("Stella", 4.0, 16.0);  // Straight A so far
  19.   student one ("one should be 3.0", 0.0, 0.0);
  20.   one.completedCourse( 4.0, 2.0 );
  21.   one.completedCourse( 4.0, 4.0 );  // 4 credit A
  22.   display( one );
  23.   display( aStudent );
  24.   display( anotherStudent );
  25.  
  26.   // Finish branch coverage testing of standing
  27.   student two("two", 100.0, 30.0);
  28.   student three( "three", 30.05, 100.0 );
  29.   student four("four" , 60.0, 100.0 );
  30.   student five("five ", 60.05, 100.0);
  31.   student six ("six " , 90.0, 100.0);
  32.   student seven("seven", 90.05, 100.0 );
  33.  
  34.   cout << one.standing() << endl;
  35.   cout << two.standing() << endl;
  36.   cout << three.standing() << endl;
  37.   cout << four.standing() << endl;
  38.   cout << five.standing() << endl;
  39.   cout << six.standing() << endl;
  40.   cout << seven.standing() << endl;
  41.  
  42.   return 0;
  43. }
  44.  
  45.  
  46. student.h
  47. #ifndef STUDENT_H
  48. #define STUDENT_H
  49.  
  50. #include <iostream>
  51. #include <string>
  52. using namespace std;
  53.  
  54. class student {
  55. public:
  56. //--constructors
  57.   student();
  58.   // post: Initialize a student object with a name as "?name?,"
  59.   //       0.0 credits, and 0.0 quality points
  60.  
  61.   student(string initName, double initCredits, double initQualityPoints);
  62.   // post: Initialize a student object with this 3 argument constructor
  63.   //          student("Delaisio, Donna," 30.0, 120.0);
  64.   //       A straight A sophomore at one school
  65.  
  66. //--modifier
  67.   void completedCourse(double credits, double numericGrade);
  68.   // post: record a completed course by adding credits to my_credits
  69.   //       and incrementing the qualityPoints by (credits * numericGrade)
  70.   //          aStudent.completedCourse(4.0, 3.67)  // a 4 credit A- perhaps
  71.  
  72. //--accessors
  73.   double GPA() const;
  74.   // post: return the current grade point average as the accumulated 
  75.   //       quality points divided by the total number of credits.
  76.  
  77.   string standing() const;
  78.   // post: use selection to return the current standing as either
  79.   //       Freshman, Sophomore, Junior, or Senior.
  80.  
  81.   string name() const;
  82.   // post: return the student's name
  83.  
  84. private:
  85.   string my_name;
  86.   double my_credits;  // Total credits completed
  87.   double my_qualityPoints; // sum of credits multiplied by grades
  88. };
  89.  
  90. #endif
  91.  
  92.  
Jul 20 '10 #1
4 1799
donbock
2,426 Recognized Expert Top Contributor
Please describe the problems you're having with student.cpp.
Jul 21 '10 #2
Oralloy
988 Recognized Expert Contributor
From a quick, simple inspection, I see the following two issues with student.cpp:

student::GPA() has a return statement with no value.
student::standi ng() has a code path which does not encounter a return statement.

Try resolving these issues and then give us a better description of the problems you're having.

Also, please use code tags. They makes reading source code sooooo much easier.
Jul 21 '10 #3
lafayettejohnson
7 New Member
The first error I am getting is C2065: '“Freshman”‘: undeclared identifier. Any more help would be greatly appreciated, if you can’t tell I am new to this c++ programming and this summer class is killing me.

student.cpp
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>    // for ostream << and istream >>
  2. #include <string> 
  3. #include "student.h"
  4. using namespace std;
  5.  
  6.  
  7.  
  8. student::student()
  9. {
  10.   my_name = "?name?";
  11.   my_credits = 0.0;
  12.   my_qualityPoints = 0.0;
  13. }
  14.  
  15. student::student(string initName, double initCredits, double initQualityPoints)
  16. {
  17.   my_name = initName;
  18.   my_credits = initCredits;
  19.   my_qualityPoints = initQualityPoints;
  20. }
  21.  
  22. //--modifiers
  23.  
  24. void student::completedCourse(double credits, double numericGrade)
  25. {
  26. my_credits = my_credits + credits;
  27. my_qualityPoints = my_qualityPoints + (credits * numericGrade), credits * numericGrade;
  28. }
  29.  
  30.  
  31. //--accessors
  32. double student::GPA() const
  33. {
  34.     double results;
  35. results = my_qualityPoints / my_credits;
  36.   return results;
  37. }
  38. string student::standing() const
  39. {
  40.  
  41. if( my_credits < 30) 
  42.   return “Freshman”;
  43. if (my_credits >= 30)
  44. return “Sophomore”;
  45. if (my_credits >= 60)
  46. return “Junior”;
  47. if (my_credits >=90)
  48. return “Senior”;
  49. else
  50. return 0;
  51. }
  52. string student::name() const
  53. {
  54. return my_name;
  55. }
  56.  
  57.  
main.cpp
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include "student.h" // this includs student.h
  4. #include "compfun.h"     // for decimals
  5.  
  6. using namespace std;
  7.  
  8. void display(student aStudent)
  9. {
  10.   decimals(cout, 2);
  11.   cout << "{ student: " << aStudent.name();
  12.   cout << ", GPA = " << aStudent.GPA() << " }" << endl;
  13. }
  14.  
  15. int main()
  16. { // test drivbe student: this main will vary a,mongst students
  17.   student aStudent("Nguyen", 36.5, 123.5);
  18.   student anotherStudent("Stella", 4.0, 16.0);  // Straight A so far
  19.   student one ("one should be 3.0", 0.0, 0.0);
  20.   one.completedCourse( 4.0, 2.0 );
  21.   one.completedCourse( 4.0, 4.0 );  // 4 credit A
  22.   display( one );
  23.   display( aStudent );
  24.   display( anotherStudent );
  25.  
  26.   // Finish branch coverage testing of standing
  27.   student two("two", 100.0, 30.0);
  28.   student three( "three", 30.05, 100.0 );
  29.   student four("four" , 60.0, 100.0 );
  30.   student five("five ", 60.05, 100.0);
  31.   student six ("six " , 90.0, 100.0);
  32.   student seven("seven", 90.05, 100.0 );
  33.  
  34.   cout << one.standing() << endl;
  35.   cout << two.standing() << endl;
  36.   cout << three.standing() << endl;
  37.   cout << four.standing() << endl;
  38.   cout << five.standing() << endl;
  39.   cout << six.standing() << endl;
  40.   cout << seven.standing() << endl;
  41.  
  42.   return 0;
  43. }
  44.  
  45.  
  46. student.h
  47. #ifndef STUDENT_H
  48. #define STUDENT_H
  49.  
  50. #include <iostream>
  51. #include <string>
  52. using namespace std;
  53.  
  54. class student {
  55. public:
  56. //--constructors
  57.   student();
  58.   // post: Initialize a student object with a name as "?name?,"
  59.   //       0.0 credits, and 0.0 quality points
  60.  
  61.   student(string initName, double initCredits, double initQualityPoints);
  62.   // post: Initialize a student object with this 3 argument constructor
  63.   //          student("Delaisio, Donna," 30.0, 120.0);
  64.   //       A straight A sophomore at one school
  65.  
  66. //--modifier
  67.   void completedCourse(double credits, double numericGrade);
  68.   // post: record a completed course by adding credits to my_credits
  69.   //       and incrementing the qualityPoints by (credits * numericGrade)
  70.   //          aStudent.completedCourse(4.0, 3.67)  // a 4 credit A- perhaps
  71.  
  72. //--accessors
  73.   double GPA() const;
  74.   // post: return the current grade point average as the accumulated 
  75.   //       quality points divided by the total number of credits.
  76.  
  77.   string standing() const;
  78.   // post: use selection to return the current standing as either
  79.   //       Freshman, Sophomore, Junior, or Senior.
  80.  
  81.   string name() const;
  82.   // post: return the student's name
  83.  
  84. private:
  85.   string my_name;
  86.   double my_credits;  // Total credits completed
  87.   double my_qualityPoints; // sum of credits multiplied by grades
  88. };
  89.  
  90. #endif
  91.  
  92.  
[/quote]
I am still having Problems getting the student.cpp to compile. the first errorIam getting is C2065: '“Freshman”' : undeclared identifier. Any more help would be greatly appreciated if you cant tell Iam new to this c++ programing and this summer class is killing me.
Jul 24 '10 #4
Oralloy
988 Recognized Expert Contributor
I'll assume that you're seeing that error at line 42 of student.cpp.

Looking at your code, it looks like your editor is putting balanced quotes in place of the C++ double quote.

Your code:
Expand|Select|Wrap|Line Numbers
  1. if( my_credits < 30)  
  2.   return “Freshman”; 
Probably should read
Expand|Select|Wrap|Line Numbers
  1. if( my_credits < 30)  
  2.   return "Freshman"; 
Jul 26 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3852
by: Greg Baker | last post by:
I don't know what standard protocol is in this newsgroup. Am I allowed to post code and ask for help? I hope so.. :) Here's my problem: I am trying problem 127 of the valladolid online contests (http://online-judge.uva.es/p/v1/127.html). The program I wrote seems to work fine, but it takes way too much memory to run. I am not that good at programming C++, unfortunately, so I can't seem to find my memory leak. As far as I can tell,...
1
1145
by: Boobie | last post by:
this little ajax demo app here: http://htmldb.oracle.com/pls/otn/f?p=25322:2 No complaint with FF - works as I intended. But IE is not getting it. e.g. 1) Last inserted element not getting fade effect but ALWAYS the first one. 2) Link on bottom does not delay appearance as I want.
5
2059
by: Marc Bishop | last post by:
I'm trying to get this to work but i'm at a loss as to how. i've searched google without much help code Dim ArrCart As new ArrayList() ArrCart = CType(Session("sesCart"), ArrayList) ArrCart.add(sID & ",1") Session("sesCart") = ArrCart So what i want to do is maintain my Arraylist of items in a session.
0
800
by: James | last post by:
Hello, I'm trying to make a very simple shopping cart using cookies and ASP. I want to store two variables for each item in the cart (one for the stock item, and one for its quantity). How do I go about reading in a list of stock items (variables) and their quantities?
10
2032
by: B Williams | last post by:
I have been working with this code for a better part of the day and I can't figure out where I am making a mistake. I can only imagine it is when I declare multiple paramaters on the constructor because the program compiles with just one parameter. Can someone look at this and tell me where I made my error? This is the error I get while trying to compile. error C2664: 'GradeBook::GradeBook(const GradeBook &)' : cannot convert...
12
1931
by: MQ.john | last post by:
//Working Example: #include <stdio.h> #include <time.h> int main () { time_t rawtime; /* define rawtime as time_t */ time ( &rawtime );
9
3764
by: siggi | last post by:
Hi all, as a newbie I have problems with formatting code of downloaded programs, because IDLE's reformatting capabilities are limited . Incorrect indentation, mixing of TAB with BLANKs or eol are often very nasty to correct. Is there a simple code formatter that first removes all indentations and then refomats correctly? Please help!
1
3458
by: mikeguy3086 | last post by:
Here is what I'm trying to achieve: I'm making a site that is basically a big slide show which is insignificant, but it has to be really minimalistic. So what I did was make an invisible button that is over the entire 900x400 rectangle. Basically what I want and as far as I got was getting it so that when you scroll over the button, the blank menu drops down. And when you scroll off it retracts and goes back up. Here is my code //this is...
3
1808
by: Porkie999 | last post by:
-----------------------------------------------------------------------QUESTION hi i am really stuck with this and its only a small problem. i want to be able to type ......... dsfsjfjsjjfs in User Box fjdjskfjds in password box www.thescripts.com in website box then i want to have a button which says "save" which then saves the 3 above pieces of text into a notepad file. So like I said I want to be able to type a login, password and...
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.