We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More


Dear Students! Share your Assignments / GDBs / Quizzes files as you receive in your LMS, So it can be discussed/solved timely. Add Discussion

How to Add New Discussion in Study Group ? Step By Step Guide Click Here.

                          Assignment No. 02
                        Semester: Fall 2013

             CS201: Introduction to Programming

Total Marks: 20

 

Due Date: 27/01/2014

 

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

Objective:

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.

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 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:

 

+ How to Follow the New Added Discussions at Your Mail Address?

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?


See Your Saved Posts Timeline

Views: 6339

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

Attachments:

Replies are closed for this discussion.

Replies to This Discussion

Please Discuss here about this assignment.Thanks

Our main purpose here discussion not just Solution

We are here with you hands in hands to facilitate your learning and do not appreciate the idea of copying or replicating solutions.

#include<iostream.h>
#include<conio.h>

class myClass
{
private :
char*str, alphabet;
public:
myClass()
{
str = new char[10];
cout"Default Constructor is called ..... and default id is bc110401299 \n";
}
void setId(char *id)
{
str = new char[10];
strcpy(str,id);
}
char * getId()
{
return str;
}
void countfunction()
{
cout"\nEnter letter you want to count: ";
cin>>alphabet;
int i =0, count = 0;
while(str[i] != '\0')
{
if(alphabet == str[i])
{
count++;
}
i++;
}
cout"The total letters "alphabet" in your student id : "countendl;
}
~myClass()
{
delete[]str;
cout"\nDestructor called ...... and object has destroyed \n";
cout"Press any key to continue ..... ";getch();
}
};
main()
{
myClass obj;
obj.setId("bc110401299");
cout"Your id is " obj.getId();
obj.countfunction();

}

Attachments:

.cpp has no error but if you copy the above code you face 6 errors

1 - cout"Your id is " obj.getId(); = cout"Your id is " obj.getId();

2 - cout"Press any key to continue ..... ";getch(); = cout"Press any key to continue ..... ";getch();

3 - cout"\nDestructor called ...... and object has destroyed \n"; = cout"\nDestructor called ...... and object has destroyed \n";

4 - cout"The total letters "alphabet" in your student id : "countendl; = cout"The total letters "alphabet" in your student id : "countendl;

5 - cout"\nEnter letter you want to count: "; = cout"\nEnter letter you want to count: ";

6 - cout"Default Constructor is called ..... and default id is bc110401299 \n"; = cout"Default Constructor is called ..... and default id is bc110401299 \n";

These errors r just due to missing less than sign.

Just put double less than sign after every cout.

Dear Students Don’t wait for solution post your problems here and discuss ... after discussion a perfect solution will come in a result. So, Start it now, replies here give your comments according to your knowledge and understandings....

//created by www.vustudents.ning.com
#include<iostream>
#include<conio.h>
using namespace std;
//www.vustudents.ning.com
class myClass
{
private :
char*str, alphabet;
public:
myClass()
{
str = new char[10];
cout"Default Constructor is called ..... and default id is MC123456789 \n";//www.vustudents.ning.com
}
void setId(char *id)
{
str = new char[10];
strcpy(str,id);
}
char * getId()
{
return str;
}//www.vustudents.ning.com
void countfunction()
{
cout"\nEnter letter you want to count: ";//created by www.vustudents.ning.com
cin>>alphabet;
int i =0, count = 0;
while(str[i] != '\0')//www.vustudents.ning.com
{
if(alphabet == str[i])
{
count++;//created by www.vustudents.ning.com
}
i++;
}
cout"The total letters "alphabet" in your student id : "countendl;//www.vustudents.ning.com
}
~myClass()
{
delete[]str;
cout"\nDestructor called ...... and object has destroyed \n";//www.vustudents.ning.com
cout"Press any key to continue ..... ";getch();
}
};
main()
{
myClass obj;
obj.setId("MC123456789");//created by www.vustudents.ning.com
cout"Your id is " obj.getId();
obj.countfunction();

}//www.vustudents.ning.com

enjoy full solution if you have facing any problem about this assinment please reply in this group

it has 10 errors

#include<iostream>
#include<conio.h>
using namespace std;
class myClass
{
private :
char*str, alphabet; 
public:
myClass() // this is Default Constructor class name and function name is same
{
cout"Default Constructor is called ..... and default id is DC130400104 \n";
}


void setId(char *id)
{
str = new char[10];// setting string array character
strcpy(str,id); // copied ID value in str varaible
}
char * getId() //ID is DC130400104 return when we call this function through object
{
return str;
}

~myClass() //this is Destructor
{
delete[]str;
cout "\n Destructor called ...... and object has destroyed \n";
cout"Press any key to continue ..... ";getch();
}
};

it has 3 errors

#include <cstdlib>
#include <iostream>

using namespace std;

char *str = "DC130400104";
void countfunction()
{
char alpha;
cout "Enter value for match= ";
cin >> alpha;
int i=0,count=0;
while(str[i] != '\0')
{
if (alpha == str[i])
{
count++;
}
i++;

}
cout "Your Alpha is =" alpha "Count val is = " count++;
}

main()
{
cout "DC130400104 \n";
countfunction();
system("PAUSE");
}

RSS

Latest Activity

Soha waris replied to + M.Tariq Malik's discussion EDU402 Curriculum Development Assignment No 01 Fall 2019 Solution & Discussion in the group EDU402 Curriculum Development
15 minutes ago
Profile IconSoha waris and ALI HASSAN joined + M.Tariq Malik's group
15 minutes ago
zobialatif posted a discussion
15 minutes ago
maria ali added a discussion to the group STA630 Research Methods
51 minutes ago
maria ali joined + M.Tariq Malik's group
52 minutes ago
+!!! Annie !!!+ liked + M.Tariq Malik's group EDU302 Human Development and Learning
58 minutes ago
+!!! Annie !!!+ liked №Oř's group Novels and Famous e books
58 minutes ago
+!!! Annie !!!+ liked + M.Tariq Malik's group CS204 Cyber Law
58 minutes ago
+!!! Annie !!!+ liked + M.Tariq Malik's group EDU433 Professionalism in Teaching
58 minutes ago
+!!! Annie !!!+ liked + M.Tariq Malik's group EDU654 Addressing problems of learning through technology and pedagogy
58 minutes ago
+!!! Annie !!!+ liked + M.Tariq Malik's group EDU630 Research Project - Education
58 minutes ago
+!!! Annie !!!+ liked + M.Tariq Malik's group TPT620 Teaching Practice (Long Term)
58 minutes ago
Ahad Kharal replied to + M.Tariq Malik's discussion CS625 Professional Practices Assignment No 01 Fall 2019 Solution & Discussion in the group CS625 Professional Practices
1 hour ago
Ahad Kharal joined + M.Tariq Malik's group
1 hour ago
DANI added a discussion to the group MGT101 Financial Accounting
1 hour ago
abdul ghafoor replied to + M.Tariq Malik's discussion PSY404 Assignment No 01 Fall 2019 Solution & Discussion Due Date: 20-11-2019 in the group PSY404 Abnormal Psychology
1 hour ago
abdul ghafoor replied to + M.Tariq Malik's discussion PSY404 Assignment No 01 Fall 2019 Solution & Discussion Due Date: 20-11-2019 in the group PSY404 Abnormal Psychology
1 hour ago
Profile IconAli Haider, samar bilal and + '' Tanveer '' joined + M.Tariq Malik's group
1 hour ago
ALEENA replied to + M.Tariq Malik's discussion How to Prepare The Mid Term Exams & Study in VU
1 hour ago
Isha Chuhdary updated their profile
1 hour ago

Today Top Members 

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

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