We have been working very hard since 2009 to facilitate in your learning Read More. We can't keep up without your support. Donate Now.

www.vustudents.ning.com

 www.bit.ly/vucodes + Link For Assignments, GDBs & Online Quizzes Solution www.bit.ly/papersvu + Link For Past Papers, Solved MCQs, Short Notes & More

# CS201 Assignment No. 02 Solution & Discussion Due Date: 27-01-2014

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

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

Views: 6425

Attachments:

Replies are closed for this discussion.

### Replies to This Discussion

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");
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
obj.countfunction();

}//www.vustudents.ning.com

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");
}

## Latest Activity

Kinz@ MuGhaL updated their profile
4 hours ago
Kinz@ MuGhaL joined +M.Tariq Malik's group

### SOC101 Introduction to Sociology

5 hours ago
Kinz@ MuGhaL joined +M.Tariq Malik's group

### PSY101 Introduction to Psychology

5 hours ago
Kinz@ MuGhaL joined +M.Tariq Malik's group

### PAK301 Pakistan Studies

5 hours ago
Kinz@ MuGhaL joined +M.Tariq Malik's group

### ENG501 History of English Language

5 hours ago
Muhammad Bilal replied to Imtiaz Waqar's discussion GDB No. 1 STA630 - Research Methods in the group STA630 Research Methods
5 hours ago
☆ Tina Solangi ☆ liked иαвєєℓ αнмє∂'s profile
6 hours ago
mahnoor omar, Maira Qurxam, Mr.Right and 24 more joined Virtual University of Pakistan
7 hours ago
8 hours ago
Hacker updated their profile
9 hours ago
Imtiaz Waqar added a discussion to the group STA630 Research Methods

### GDB No. 1 STA630 - Research Methods

11 hours ago
Imtiaz Waqar joined +M.Tariq Malik's group

11 hours ago

### MTH202 Discrete Mathematics

11 hours ago
11 hours ago
11 hours ago
Maria joined +M.Tariq Malik's group

### EDU101 Foundations of Education

11 hours ago
Maria and SafeerZaidi are now friends
11 hours ago
SafeerZaidi liked Maria's profile
11 hours ago
Tasha Malik posted a status
"Bio 201 Assignment # 2 Solution https://youtu.be/Gowjc67WZ4c"
12 hours ago
Maria liked +M.Tariq Malik's profile
13 hours ago