472,353 Members | 1,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

error C2228: left of '.grade' must have class/struct/union

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <iomanip>
  5. using namespace std;
  6. const int NO_OF_STUDENTS=20;
  7. struct studentType
  8. {
  9.     string studentFName;
  10.     string studentLName;
  11.     int testScore;
  12.     char grade;
  13. };
  14. void getData(studentType sList[], int NO_OF_STUDENTS);
  15. void calculateGrade(studentType sList[], int NO_OF_STUDENTS);
  16. void printResult(const studnetType sList[], int NO_OF_STUDENTS);
  17. int main()
  18. {
  19.     studentType sList[NO_OF_STUDENTS];
  20.     getData(sList, NO_OF_STUDENTS);
  21.     calculateGrade(sList, NO_OF_STUDENTS);
  22.     printResult(sList, NO_OF_STUDENTS);
  23.     return 0;
  24. }
  25.  
  26. void getData(const studentType sList[], int listSize)
  27. {
  28.     ifstream inData;
  29.     ofstream outData;
  30.     inData.open("C:\\student.txt");
  31.     for (int i=0;i<NO_OF_STUDENTS;i++)
  32.         inData>>sList[i].studentFName>>sList[i].studentLName>>sList[i].testScore;
  33.     outData.close();
  34. }
  35.  
  36. void calculateGrade(studentType sList[], int listSize)
  37. {
  38.     for (int i=0;i<NO_OF_STUDENTS;i++)
  39.     {
  40.         switch(sList[i].testScore/10)
  41.         {
  42.         case 0:
  43.         case 1:
  44.         case 2:
  45.         case 3:
  46.         case 4:
  47.         case 5:
  48.             sList[i].grade='F';
  49.             break;
  50.         case 6:
  51.             sList[i].grade='D';
  52.             break;
  53.         case 7:
  54.             sList[i].grade='C';
  55.             break;
  56.         case 8:
  57.             sList[i].grade='B';
  58.             break;
  59.         case 9:
  60.         case 10:
  61.             sList[i].grade='A';
  62.             break;
  63.         }//closes switch
  64.     }//closes for loop
  65. }//closes function
  66.  
  67. void printResult(const studnetType sList[], int listSize) (THIS IS WHERE I'M HAVING TROUBLE
  68. {
  69.     for (int d=0;d<NO_OF_STUDENTS;d++)
  70.     {
  71.         cout<<sList[d].studentFName<<sList[d].studentLName<<sList[d].testScore<<sList[d].grade<<endl;
  72.     }
  73. }
  74.  

1>------ Build started: Project: project5, Configuration: Debug Win32 ------
1>Compiling...
1>project5.cpp
1>c:\documents and settings\yese\my documents\visual studio 2005\projects\project5\project5.cpp(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\yese\my documents\visual studio 2005\projects\project5\project5.cpp(16) : error C2146: syntax error : missing ',' before identifier 'sList'
1>c:\documents and settings\yese\my documents\visual studio 2005\projects\project5\project5.cpp(22) : error C2660: 'printResult' : function does not take 2 arguments
1>c:\documents and settings\yese\my documents\visual studio 2005\projects\project5\project5.cpp(32) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion)
1> c:\program files\microsoft visual studio 8\vc\include\istream(1137): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Ele m,_Traits> &,signed char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(1139): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Ele m,_Traits> &,signed char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(1141): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Ele m,_Traits> &,unsigned char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(1143): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Ele m,_Traits> &,unsigned char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\string(593): or 'std::basic_istream<_Elem,_Traits> &std::operator >><char,std::char_traits<char>,std::allocator<_Ty> >(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Ax> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ty=char,
1> _Ax=std::allocator<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(155): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(161): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(168): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(175): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(194): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(228): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(247): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(273): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(291): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(309): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__w64 unsigned long &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(329): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(348): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(367): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(float &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(386): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(404): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(422): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(void *&)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 8\vc\include\istream(441): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> while trying to match the argument list '(std::ifstream, const std::string)'
1>c:\documents and settings\yese\my documents\visual studio 2005\projects\project5\project5.cpp(67) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\yese\my documents\visual studio 2005\projects\project5\project5.cpp(67) : error C2146: syntax error : missing ',' before identifier 'sList'
1>c:\documents and settings\yese\my documents\visual studio 2005\projects\project5\project5.cpp(71) : error C2065: 'sList' : undeclared identifier
1>c:\documents and settings\yese\my documents\visual studio 2005\projects\project5\project5.cpp(71) : error C2228: left of '.studentFName' must have class/struct/union
1>c:\documents and settings\yese\my documents\visual studio 2005\projects\project5\project5.cpp(71) : error C2228: left of '.studentLName' must have class/struct/union
1>c:\documents and settings\yese\my documents\visual studio 2005\projects\project5\project5.cpp(71) : error C2228: left of '.testScore' must have class/struct/union
1>c:\documents and settings\yese\my documents\visual studio 2005\projects\project5\project5.cpp(71) : error C2228: left of '.grade' must have class/struct/union
1>Build log was saved at "file://c:\Documents and Settings\Yese\My Documents\Visual Studio 2005\Projects\project5\Debug\BuildLog.htm"
1>project5 - 11 error(s), 0 warning(s)



i'm supposed to display the list in the last function...can anyone please help?
Dec 7 '07 #1
2 14708
gpraghuram
1,275 Expert 1GB
HI,
Whenever you define a struuct you shuld use struct keyword while declaring variables of that type or else you shuld do a typedef.

Expand|Select|Wrap|Line Numbers
  1. //your have to change these
  2. void getData(struct studentType sList[], int NO_OF_STUDENTS);
  3. void calculateGrade(struct studentType sList[], int NO_OF_STUDENTS);
  4. void printResult(const struct studnetType sList[], int NO_OF_STUDENTS);
  5.  
  6. //or change the declaraion like
  7. typedef struct _studnetType
  8. {
  9. //
  10. }studnetType ;
  11. //then you can have the code as it is.
  12.  

Raghuram
Dec 7 '07 #2
HI,
Whenever you define a struuct you shuld use struct keyword while declaring variables of that type or else you shuld do a typedef.

Expand|Select|Wrap|Line Numbers
  1. //your have to change these
  2. void getData(struct studentType sList[], int NO_OF_STUDENTS);
  3. void calculateGrade(struct studentType sList[], int NO_OF_STUDENTS);
  4. void printResult(const struct studnetType sList[], int NO_OF_STUDENTS);
  5.  
  6. //or change the declaraion like
  7. typedef struct _studnetType
  8. {
  9. //
  10. }studnetType ;
  11. //then you can have the code as it is.
  12.  

Raghuram


no, it wasn't that at all...i realized i spelled student incorrectly in that function (studnet)...that solved all my errors. haha, i feel so dumb. thanks though!
Dec 7 '07 #3

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

Similar topics

6
by: c++newbie | last post by:
Hi all, I try to compile the following classes: main.cpp: #include <algorithm> #include <iostream> #include <fstream> #include <iterator>
3
by: lelle | last post by:
Hi everyone. I discovered a strange phenomena that I'm curios whether anyone else have seen. DB2 V8 fixpak 7a redhat. First some ddl (sorry about...
7
by: inkexit | last post by:
I'm getting these two error mesages when I try to compile the below source code: error C2065: 'input_file' : undeclared identifier error C2228:...
7
by: GRoll35 | last post by:
I have 3 files here - Header/Implementation/Driver All it has to do is send the user's input (age)..to the class and the class will figure out...
1
by: uday | last post by:
Hi, I am new to visual c++ and I am trying to compile a Decoder project with library in it. I tried to create a win32 console application and...
2
by: cr55 | last post by:
I was wondering if anyone can help me with this programming code as i keep getting errors and am not sure how to fix them. The error code displayed...
2
by: dblbac | last post by:
i have gone through my c++ program and i keep getting the same error messages: error C2065: 'indata' : undeclared identifier error C2228: left of...
6
by: hsmit.home | last post by:
Hello, I came across a strange error and it's really been bugging me. Maybe someone else has come across this and any insight would be...
2
by: Gunners | last post by:
#include<iostream.h> #include<conio.h> #include<stdio.h> #include<stdlib.h> struct st_base { char name; int roll_no; int...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.