473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 14874
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 the length of this): CREATE TABLE...
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: left of '.eof' must have class/struct/union type ...
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 the price of the ticket. I'm suppose to create the...
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 tried to add a compiled static library to it. I...
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 now is error: C2228: left of '.rent' must have...
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 '.open' must have class/struct/union my program...
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 appreciated. What I'm trying to accomplish is using...
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 s1,s2,s3,s4,mks; float percentage;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.