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.

                          Assignment No. 02
                        Semester: Fall 2013

             CS201: Introduction to Programming

Total Marks: 20


Due Date: 27/01/2014



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, no reward will be given in any case.


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

  • Basic concepts of C/C++ classes and objects
  • Dealing with Data members and member functions
  • Initialization of objects
  • Constructor
  • Destructor
  • Dynamic memory Allocation using new operator.


  • 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.





Problem Statement

Write a program using class(constructor, destructor, other member functions) to find the frequency of letters (small and capital alphabet or digit) from your student id character string. For example, frequency of letter ‘4’ in the string of a student id: “MC124514517” is 2.


Detailed Description:

You are required to write a program which contains a class myClass having the following data members:


         char*str,  alphabet;

and the following member functions:

  • myClass();
  • void setId(char *);
  • char * getId();
  • void countfunction();
  • ~myClass();

The main() function should create an object of myClass and through this object member functions are called one by one. When the object is created then constructor of myClass should dynamically allocate the memory using new operator for your VUID and displays a message after storing the default id in data member character pointer str.

     “Default Constructor is called and default id is MC123456789”

Similarly, setId() member function when called with your VUID passed as parameter, should set the value of data member character pointer str with your VUID.

getId() function should return the value of data member character pointer str to the main(), then following message with your VUID should be displayed:

      “Your ID is MC120403765”

Finally countfunction() must get input (any alphabet) from user by displaying the message,

     “Enter letter you want to count:”

Then this function counts frequency of the specified letter from your VUID and displays it.

Destructor at the end of the program should be called and display message:

“Destructor called… and object has destroyed”

Sample output of program:


Views: 6516


Replies are closed for this discussion.

Replies to This Discussion

.h nhi likhna...

.h remove krna hai..

just write


now i face that error

[Error] 'strcpy' was not declared in this scope

when i write the function in the private i got the desire out put when in public i face the some error. can i change as i want to get the output?

#include<string.h> headr use kro


using namespace std;

like as


using namespace std;


use the header file #include<string.h>

again error

 [Error] expected ';' before 'alphabet'

u mistake in this line

char*str, alphabet;

u missing comma here... char*str, 

one error remove then next error appeare

 [Error] 'strcpy' was not declared in this scope

u used?

using namespace std;

thanks malika n zahid bhai. i done my assigment.

Welcome  CoCo


Looking For Something? Search Below

Latest Activity

Hania Khalid Shariff is now friends with Mr Siren Head and Huma Ahmad
17 minutes ago
saba zulfqar posted blog posts
3 hours ago
+ ¢αяєℓєѕѕ gιяℓ updated their profile
3 hours ago
saba zulfqar and Hania Khalid Shariff are now friends
6 hours ago
Mr Siren Head replied to Hania Khalid Shariff's discussion zero semester
11 hours ago
Profile Iconshahzad Hussain and Umar Farooq joined Virtual University of Pakistan
12 hours ago
Huma Ahmad liked Hania Khalid Shariff's profile
22 hours ago
BBA(6th smes) left a comment for Rimsha mujahid
23 hours ago

VIP Member Badge & Others

How to Get This Badge at Your Profile DP


Management: Admins ::: Moderators

Other Awards Badges List Moderators Group

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

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