|
Thank you.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
You are welcome.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
I have n no of objects of a class. So what I want to do is - I want to save those data to a file when my application exit.
So how it is possible to write multiple objects of same class to a file and read that file to make objects of the same class.
Thanks in advance.
|
|
|
|
|
Google "C++ Serialization"
There are many ways to do this; but it seems using the Boost serialization library is widely recommended.
I'd rather be phishing!
|
|
|
|
|
Or VARIANT, if it's Win32.
|
|
|
|
|
I can create toolbars to support small and large icons with code like this :
{
if (!m_StandardToolBar.CreateEx(this, TBSTYLE_FLAT, style| WS_VISIBLE , CRect(1,1 , 1, 1), ITB_STANDARD_TOOLBAR) )
{
TRACE0("Failed to create toolbar\n");
return false; }
CMFCToolBarInfo info;
info.m_uiColdResID = ITB_STANDARD_TOOLBAR;
info.m_uiHotResID = ITB_STANDARD_TOOLBAR;
info.m_uiLargeColdResID = ITB_STANDARD_LARGE_TOOLBAR;
info.m_uiLargeHotResID = ITB_STANDARD_LARGE_TOOLBAR;
m_StandardToolBar.LoadToolBarEx( ITB_STANDARD_TOOLBAR, info , FALSE);
m_StandardToolBar.SetWindowText( CMbString::mbLoadString(IDS_TOOLBAR_STANDARD));
}
When changing the "DPI" (what was the "large font/small font) settings before) MFC (Win32) will automagically resize the toolbar bitmaps to fit the new settings.
There are now 3 settings :
100% (smaller, default), 125% (medium) and 150% (Larger)
If the default small toolbar button is 16x16, then the other sizes will be 20x20 and 24x24
If the default large toolbar button is 32x32, then the other sizez will be 40x40 and 48x48.
Now if I have to do this "by the book" I would need to generate toolbars with buttons 16x16, 20x20, 24x24, 32x32, 40x40 and 48x48.
so for each toolbar I create I will have something like :
// pseudo code
UINT smallToolbarID;
if ( DPI == smaller )
{
smallToolbarID = 16x16;
largeToolbarID = 32x32
}
else if ( DPI == medium )
{
smallToolbarID = 20x20;
largeToolbarID = 40x40
}
else if ( DPI == larger)
{
smallToolbarID = 24x24;
largeToolbarID = 48x48
}
if (!m_StandardToolBar.CreateEx(this, TBSTYLE_FLAT, style| WS_VISIBLE , CRect(1,1 , 1, 1), ITB_STANDARD_TOOLBAR) )
{
TRACE0("Failed to create toolbar\n");
return false; }
CMFCToolBarInfo info;
info.m_uiColdResID = smallToolbarID;
info.m_uiHotResID = smallToolbarID;
info.m_uiLargeColdResID = largeToolbarID;
info.m_uiLargeHotResID = largeToolbarID;
m_StandardToolBar.LoadToolBarEx( ITB_STANDARD_TOOLBAR, info , FALSE);
m_StandardToolBar.SetWindowText( CMbString::mbLoadString(IDS_TOOLBAR_STANDARD));
Meaning that for each toolbar, I will have 6 different bitmaps to maintain?
Am I thinking this straight or is there a catch somewhere ?
Thanks.
Max.
I'd rather be phishing!
|
|
|
|
|
Hi
Did you go with this in the end?
Andrew
|
|
|
|
|
Respected Sir Please Tell me logical error in this code because i faced many difficulties in This Code, please solve this .
When i Execute the Code after Enter 1 Option it cannot get the name if it get the name the password field cannot execute.and more error in it like ,.
i want to get only 8 string/Number in Password but loop did not work correctly please answer me ASAP.
// student_Record_Management_C++_1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<string>
#include<stdlib.h>
#include<iomanip>
#include<stdio.h>
#include<conio.h>
using namespace std;
class Menu_Account
{
private:
int option,loop;
char name[20],pass[8],pass_1[8],color[10];
public:
void int_menu()
{
cout<<"\t\t\t-----------------------------------"<<endl;
cout<<"\t\t\t="" student="" management="" record="" system."<<endl;
="" cout<<"\t\t\t-----------------------------------"<<endl<<endl;
="" cout<<endl<<endl;
="" cout<<"\t\t\t-------------------------------"<<endl;
="" enter="" login="" id="" &="" password"<<endl;
="" cout<<"\t\t\t-------------------------------"<<endl<<endl;
="" cout<<"\t\t\t1:cretae="" new="" account."<<endl;
="" cout<<"\t\t\t2:already="" have="" accoutn."<<endl;
="" cout<<"\t\t\t3:exit."<<endl<<endl<<endl;
="" xyz:
="" cout<<"\t\t\tenter="" option:";
="" cin="">>option;
cout<<endl;
switch(option)
="" {
="" case="" 1:
="" return="" account_create();
="" break;
="" 2:
="" void="" login_id();
="" 3:
="" exit(0);
="" default:
="" cout<<"enter="" right="" input"<<endl;
="" goto="" xyz;
="" }
="" }
="" account_create()
="" system("cls");
="" cout<<"\t\t\t-----------------------------------"<<endl;
="" cout<<"\t\t\t="" student="" management="" record="" system."<<endl;
="" cout<<"\t\t\t-----------------------------------"<<endl<<endl;
="" cout<<endl<<endl;
="" enter="" information="" for="" new="" account."<<endl;
="" cout<<"\n\t\t\tenter="" your="" name:";
="" cin.getline(name,20);
="" password:";
="" for(loop="0;loop<8;loop++)
" cin="">>pass[loop];
}
cout<<"\n\t\t\tRe-type Password:";
cin>>pass_1;
cout<<"\n\t\t\tWhat Is Your Favorite Color:";
cin.getline(color,10);
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Menu_Account obj_1;
obj_1.int_menu();
char choice;
fstream in_file("Student.txt",ios::in|ios::app|ios::out);
do
{
obj_1.Account_Create();
in_file.write(reinterpret_cast<char *="">(&obj_1),sizeof(obj_1));
cout<<"\nDo You Want To Add More Data:";
cin>>choice;
}while(choice=='y'||choice =='Y'|| choice=='1');
in_file.close();
system("pause");
return 0;
}
|
|
|
|
|
Looking at your code there are a number of issues. For example you call Account_Create() in your int_menu() function, and then call it again immediately on return. You should take all the menus and input code out of your class and just use the class for holding and manipulating its data. Start with a basic class definition and one function for getting details from the user. Compile and test that part, use your debugger to check that it saves and manages its data correctly. Then add the next function, compile and test that, etc. etc.
|
|
|
|
|
Hi,
Can you summarize whats the purpose of this code?
Because the way you are following is not correct. But we are here to guide you, try to summarize what you did for?, what you are expecting? and what support you required... You will get help definitely
Thanks
|
|
|
|
|
Thank you For Reply Me,
i used this code for making new account of user and save this data in the file after getting all detail in the main.
Please tell me Issue and coding Style Error in this code because i am New In C++ And i learn it By Self Nobody are there for helping me .
|
|
|
|
|
|
Have you stepped through it, line by line, using the debugger?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi,
I will tell first step to follow in your code. Don't put all the operations in the body of class.. I mean that selection option using switch you write in main. Then one more mistake you did is calling the Account_Create() function before defining it. and using return Account_Create() is also not correct in switch() statement. First you do this, then hope your code will work properly.. If you didn't get also no problem, i will help you to solve this. I already did yesterday this. I don't want to give you that code and spoil you. First you try your level best with guidelines whatever so far people guided.
Nobody is perfect in this world...
Thank you.
|
|
|
|
|
Thank You For My Help,
Now I Will Try to Solve This Problem .
|
|
|
|
|
Hi,
Let me know after what you did, so that further what to do will tell.
|
|
|
|
|
CP is now ground for homeworks for free? RTFM.
|
|
|
|
|
is there any algorithm to calculate very large array(integer)'s average value? by ordinary method, there maybe danger of sum overflow.
|
|
|
|
|
If the integers are 32-bit use 64-bit (long long int ) for calculation.
You can always use double for the calculation. But this may give inexact results.
A general method is using another variable to extend the sum. This requires overflow check for each add operation and implementation of the division operation for the extended value.
|
|
|
|
|
|
A tongue-in-cheek approach:
Averaging...the easy way.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I've taken the link provided above (about cumulative average) as an inspiration to calculate the average incrementally, in a way that no intermediate value gets larger than about three times the maximum absolute value being added. Since I wasn't sure about various effects, such as the current average going negative, I added some test code and asserts to verify it actually works as intended. See the code below:
#define TEST_RANGE
#ifdef TEST_RANGE
#include <assert.h>
void minmax(const double newval, double&minv, double&maxv) {
if (newval < minv)
minv = newval;
else if (newval > maxv)
maxv = newval;
}
#endif
template <class basetype, class container_iterator>
basetype average(const container_iterator& start, const container_iterator& end) {
basetype cumulated_average = 0;
basetype cumulated_remainder = 0;
basetype addendum = 0;
#ifdef TEST_RANGE
double real_avg = 0.0;
double val_min = *start;
double val_max = *start;
double avg_min = cumulated_average;
double avg_max = cumulated_average;
double rem_min = cumulated_remainder;
double rem_max = cumulated_remainder;
#endif
long long n_values = 0;
for (auto pvalue = start; pvalue != end; ++pvalue) {
++n_values;
addendum = cumulated_remainder - cumulated_average + *pvalue;
cumulated_average += addendum/n_values;
cumulated_remainder = addendum%n_values;
#ifdef TEST_RANGE
real_avg += *pvalue;
assert((char)(n_values*cumulated_average + cumulated_remainder - real_avg) == 0);
minmax(*pvalue, val_min, val_max);
minmax(cumulated_average, avg_min, avg_max);
minmax(cumulated_remainder, rem_min, rem_max);
#endif
}
#ifdef TEST_RANGE
assert (fabs(n_values*cumulated_average - real_avg) < n_values);
real_avg /= (double)n_values;
#endif
return cumulated_average;
}
void test_average() {
char cvalues[] = { 13,7,-27, 34, -3, 22, 33, -1, 18, 29,
13,7,-27, 34, -3, 22, 33, -1, 18, 29,
13,7,-27, 34, -3, 22, 33, -1, 18, 29,
13,7,-27, 34, -3, 22, 33, -1, 18, 29,
13,7,-27, 34, -3, 22, 33, -1, 18, 29
};
auto cavg = average<char>(cvalues+0, cvalues+50);
}
The last line is how it's used. For passing the values, you can pass any pair of iterators that delimit the range, including simple pointers (as I've done here), provided that these iterators can be incremented and dereferenced. In this example, the cumulative average does go negative a few times, and the total sum adds up to 625, way above the maximum a char can hold.
Note that you may not use a signed type for n_values: I originally used a signed type, but then found that this led to some nasty signed/unsigned conversion effects. You could probably get rid of that with proper casting though.
P.S. these are the formulas I've used:
The general idea is to have two values that correspond to the rounded average, and the remainder of the division, like this:
Cum_avg(n) := sum(x1 ... xn) \ n
Cum_rem(n) := sum(x1 ... xn) % n
These two values then fulfil the follwing equation:
sum(x1...xn) = n*Cum_avg(n) + Cum_rem(n)
The values for the next iteration are then calculated based on the previous values like this:
Cum_avg(n+1) := sum(x1...xn+1) \(n+1)
= (sum(x1...xn)+xn+1) \(n+1)
= (n*Cum_avg(n)+Cum_rem(n)+xn+1) \(n+1)
= ((n+1)*Cum_avg(n)-Cum_avg(n)+Cum_rem(n)+xn+1) \(n+1)
= Cum_avg(n) + (-Cum_avg(n)+Cum_rem(n)+xn+1) \(n+1)
I've used a helper variable called addendum to hold the divisor of the second term. This term is just a sum of three values that are going to be in the normal value range, so the worst that can happen here is an overflow of that term. I still suspect that this can happen under certain circumstances, so the calculation of addendum may need some reworking!
The remainder of the next iteration is then simply the remainder of the division of addendum:
Cum_rem(n+1) := addendum % (n+1)
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Hi,
I think I'm getting different behaviours with the code below for Release and Debug compiles.
FILE* in ;
err = fopen_s (&in, fileName.c_str(), "r");
if (!in) {
std::cerr << "cannot open input file '" << fileName << "'" << std::endl;
return;
}
char buff[1024];
while (fgets(buff, 1024, in)) {
std::string line=buff;
line is getting the characters ok when compiled in Debug. In Release though, line is BadPtr.
I guess I'm doing the initialization wrong, but I don't see why.
|
|
|
|
|
Perhaps this[^] link will help.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
My excuses for not answering during the weekend.
As suggested by some comment on the link you posted (thank you) the problem seems to be in the fgets function. It is storing senseless data in buff for Release, and then the std::string constructor can't make sense of it.
I will try with std::getline() .
|
|
|
|
|