// TemplateExample.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
/*
This program illustrates the use of MFC Template calss(CArray<data type,data type>) and string
Handling(CString) classes, writing your own class (CStudent),
Manipulating an array of objects(CArray<>) using template classes
Included these fies in stdafx.h
#include <stdio.h>
#include <iostream.h>
#include <afx.h>
#include <afxtempl.h>
Note:
if you are getting some sort of link error in any of your program
linking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/TemplateExample.exe : fatal error LNK1120: 2 unresolved externals
Please open Project->settings menu,
after that use this open
"MFC as a static link library" in the combo box provided.
Tom
*/
/*----------------------------------- Class Header ------------------------------------------*
Name : CStudent
Date of Creation : 9/17/2004 2:42:46 PM
Type : BASE
Functionality : This class is uses to store all
information about the student.
---------------------------------------------------------------------------------------------*/
class CStudent
{
public:
CString m_strName;
int m_iAge;
CStudent()//Constructor initialize all variables here
{
m_strName="";
m_iAge=-1;
}
~CStudent()//Destructor
{
}
};
int main(int argc, char* argv[])
{
//CArray is template
CArray<CStudent,CStudent> m_StudentArray;//CArray is a doubly linked list internaly but it will act as dynamic array
int iNoOfStudents=0;
char YesOrNo;
cout<<"*************Student Database***************
";
cout<<"Please Enter Number of of students";
cin>>iNoOfStudents;
for(int i=0;i<iNoOfStudents;i++)
{
char strName[25];
CStudent Student;
cout<<"
Please Enter the student Name:-";
cin>>strName;
Student.m_strName=strName;
cout<<"
Please Enter the student Age:-";
cin>>Student.m_iAge;
//Add this information in the array for future use.
m_StudentArray.Add(Student);
}
cout<<"
Do you want to display all informations From The array m_StudentArray(y/n):-";
cin>>YesOrNo;
if(YesOrNo=='Y'||YesOrNo=='y')
{
for(int i=0;i<m_StudentArray.GetSize();i++)
{
CString strData;
strData.Format("%d)Name:-%s, Age:-%d
",i+1,
m_StudentArray[i].m_strName,m_StudentArray[i].m_iAge);
cout<<strData;
}
}
return 0;
}