Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.


CS201: Introduction to Programming Assignment No. 03 Semester: Spring 2013 Due Date:26/06/2013

Assignment No. 03
Semester: Spring 2013

CS201: Introduction to Programming

Total Marks: 20

 

Due Date:26/06/2013

 

Instructions:

Please read the following instructions carefully before submitting assignment. It should be clear that your assignment will not get any credit if:

 

  • The assignment is submitted after due date.
  • The submitted assignment does not open or file is corrupt.
  • Assignment is copied(partial or full) from any source (websites, forums, students, etc)

 

Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks. For example, if you submit code in .doc (Word document) or .txt files or .exe file or .zip no reward will be given in any case.

 

 

Objective:

 

The objective of this assignment is to provide hands on experience of:

 

  • Basic concepts of classes and objects in C/C++ language
  • Dealing with member functions
  • Parameterized constructors
  • File handling

 

 

Guidelines:

 

  • Code should be properly indented and well commented.
  • Follow C/C++ rules while writing variable names, function names etc
  • Use only dev-C++ for this assignment.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Assignment  

 

Problem Statement:     

Write the C++ program having class name studentinfo, that is used to store the VU student information: This class should store your VUID, campus id, name and father name in the following character type data members:

 

Data members:

  • VUID
  • campusID
  • Studentname
  • Fathername

 

Studentinfo class should have the parameterized constructor that is used to initialize the data members of the studentinfo class,

 

Studentinfo class should have following member functions.

  • Storefile()
  • Display()

 

Storefile() member function should store the value of all data members in the text file named “record.txt”, on separate lines in the text file as follows:  

 

ms120400400

Vlhr02

Muhammad Hussain

Muhammad Ali.

 

Display() member function reads your VUID, campusID, name and father name from the file named “record.txt”, stores them in the respective data members and displays the record.

 

Hint: 

In main() function, create the object of the class by using parameterized constructor and then call the storefile() member function to store the record of all the data members in the text file. Finally call the display() function to read the data from text file and store it in the respective data members and display all the records.

 

Sample Output:

 

Note: You have to upload only .cpp file of your assignment, do not send your assignment in .txt, .zip, .rar .doc or .docx format.

 

Views: 6482

Attachments:

Replies to This Discussion

//CS201 Introduction to Programming 
//Assignment No. 03 Solution 
//Spring 2013
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;


class StudentInfo
{

char* vuId;
char* campusId;
char* studentName;
char* fatherName;

public:

StudentInfo(char* vu_Id, char* campus_Id, char* student_Name, char* father_Name)
{
cout "Parameterized constructor is called." endl;

setVuId(vu_Id);
setCampusId(campus_Id);
setStudentName(student_Name);
setFatherName(father_Name);
}

void setVuId(char* vu_Id)
{
vuId = new char[strlen(vu_Id) + 1];
strcpy(vuId, vu_Id);
}
void setCampusId(char* campus_Id)
{
campusId = new char[strlen(campus_Id) + 1];
strcpy(campusId, campus_Id);
}
void setStudentName(char* student_Name)
{
studentName = new char[strlen(student_Name) + 1];
strcpy(studentName, student_Name);
}
void setFatherName(char* father_Name)
{
fatherName = new char[strlen(father_Name) + 1];
strcpy(fatherName, father_Name);
}
void storeFile()
{
cout "All the data members are stored in file." endl;

ofstream outFile;
char* outputFileName = "record.txt";
outFile.open(outputFileName, ios::out);
if(!outFile)
{
cout "\n Unable to open file." endl;

}
else
{

outFile vuId;
outFile endl;
outFile campusId;
outFile endl;
outFile studentName;
outFile endl;
outFile fatherName;

}
}
void display()
{

ifstream inputStream;
char* fileName = "record.txt";
inputStream.open(fileName);
if(!inputStream)
{
cout "\nCan't Open the file for read";
}
else
{

char line[100];
inputStream.getline(line, 100);
setVuId(line);
inputStream.getline(line, 100);
setCampusId(line);
inputStream.getline(line, 100);
setStudentName(line);
inputStream.getline(line, 100);
setFatherName(line);
cout "Following is your data:" endl;
cout vuId endl;
cout campusId endl;
cout studentName endl;
cout fatherName;
cout endl;
}

}

};
int main()
{

StudentInfo studentInfo("ms120400400", "Vlhr02", "Muhammad Hussain", "Muhammad Ali.");
studentInfo.storeFile();
studentInfo.display();
system("pause");
return 0;
}

yah kas tarah kam kr re ga 5.1.0.0 main

insertion operator nai osay dalo ""

Ye error kesy resolve hoga? Reply fast please.

kon sa dev c++ ka version kaam kar raha h????????????

kam sab kr rhay hain agar app ko gcc char * error a rha ha devc++ mein its mein new gcc are not sported char *

#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
class studentinfo
{
char* VUID;
char* campusID;
char* Studentname;
char* Fathername;

public: 
studentinfo(char* vu_Id, char* campus_Id, char* student_Name, char* father_Name)
{
cout "Parameterized constructor is called." endl;
setVuId(vu_Id);
setCampusId(campus_Id);
setStudentName(student_Name);
setFatherName(father_Name);
}

void setVuId(char* vu_Id)
{
VUID = new char[strlen(vu_Id) + 1];
strcpy(VUID, vu_Id);
}
void setCampusId(char* campus_Id)
{
campusID = new char[strlen(campus_Id) + 1];
strcpy(campusID, campus_Id);
}
void setStudentName(char* student_Name)
{
Studentname = new char[strlen(student_Name) + 1];
strcpy(Studentname, student_Name);
}
void setFatherName(char* father_Name)
{
Fathername = new char[strlen(father_Name) + 1];
strcpy(Fathername, father_Name);
}
void storeFile()
{
cout "All the data members are stored in file." endl;
ofstream outFile;
char* outputFileName = "record.txt";
outFile.open(outputFileName, ios::out);
if(!outFile)
{
cout "\n Unable to open file." endl;

}
else
{
outFile VUID;
outFile endl;
outFile campusID;
outFile endl;
outFile Studentname;
outFile endl;
outFile Fathername;

}
}
void display()
{
ifstream inputStream;
char* fileName = "record.txt";
inputStream.open(fileName);
if(!inputStream)
{
cout "\nCan't Open the file for read";
}
else

char line[100];
inputStream.getline(line, 100);
setVuId(line);
inputStream.getline(line, 100);
setCampusId(line);
inputStream.getline(line, 100);
setStudentName(line);
inputStream.getline(line, 100);
setFatherName(line);
cout "Following is your data:" endl;
cout VUID endl;
cout campusID endl;
cout Studentname endl;
cout Fathername endl;
}

}

};
int main()
{
studentinfo obj("ms120400400", "Vlhr02", "Muhammad Hussain", "Muhammad Ali.");
obj.storeFile();
obj.display();
system("pause");
return 0;
}

bhai is program mein errors hain plz koi error free program upload ker den

RSS

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service